Git And GitHub

Git And GitHub

In This Blog We Will Try to learn about Basics Of Git And GitHub

Β·

4 min read

Recently I have started learning a Data Structure And Algorithm Course From Kunal Kushwaha DSA Bootcamp, in the

In 4 video lecture

, he taught the fundamentals of Git And GitHub.

Git And GitHub.

Here In this Blog, I would like to share the things mentioned below:

  1. Git Basics

  2. GitHub Basics

  3. Errors Faced And Solution to it

Git Basics

Let us start with a story, Suppose when we are working on a project which consists of 5 people, then

How to track which change was made by which contributor fellow? At which part of the project At which time? Then how to track all these things, the answer is Git !!!. Git is nothing but software that tracks the project. In technical terms, it is called a Distributed Version Control System (DVCS).

GitHub is an online website used to share Git repositories. Repository means the folder in which all the changes have been saved.

Use Git bash instead of Git GUI because it will give a hands-on experience with the Command Line Interface

The first step to begin is Download Git from Git Download For Different Operating System And set it up on your local device as per the Operating System

Now let us start with Git, open it by right click on the mouse or trackpad and open git bash on Desktop

  1. mkdir project_name --> With the help of this command we will create a folder with project_name

  2. ls --> This command is used to list all the files and folders present inside the particular folder

  3. git init --> This will initialize the git repository which will track all the changes made in the folder

  4. touch filename. extension --> This command will create a file with a particular extension

  5. nano filename. extension --> This command will open the file in the git bash only

  6. cat filename. extension --> This will display all the content present inside the file.

  7. git status --> This command will tell the status of the file whether its untracked, stagging area, committed, tracked etc

8)Untracked Files --> If we try to push the folder on GitHub, then the changes made in Untracked files are not known to anyone

Let us understand an analogy Suppose you have gone to a wedding, we generally take photos with the couple, if we observe there are 4 types of people: a) People who have not taken a photo with the couple and are still not in line to take photo (Untracked File) b) People who have not taken a photo but are in queue to take photo (staged file) c) People who are clicking photos with a couple (committed files) d) People whose photos have been taken (tracked files)

  1. git add filename. extension --> This file will add a particular file in the staging area

  2. git add. --> This file will add all the files in the staging area

  3. git commit -m " Write Message here" --> Files will be committed means the photo has been taken

  4. git restore --staged filename. extension --> This command is used to remove a file from the staging area.

  5. git reset id_of_commit --> This command is used to reset the previous commit

GitHub Basics

GitHub is a website by which people from any part of the world can contribute to code.

The following are the steps to push code on Github

  1. Sign In to GitHub, go to the new repository

  2. Make the repository public And complete other details such as naming the repository, readme file etc

  3. After making the repository, copy the link to the URL

  4. Come back to Git bash and write the following code:

    • git remote add origin URL

      This connection Between GitHub Repository on the local desktop and GitHub is established.

Errors Which Can Be Faced

While completing step 4, a person may observe the error 403, which means a connection is not established properly between Git And GitHub. To solve this issue generate access tokens from GitHub, refer to the below link for help:

GitHub Personal Tokens

  1. After the error has been solved, push code on GitHub using the command below

    • git push origin master

      The above code means that we are going to push the master branch of GitHub on URL named the origin.

Branching

In general, if we look at Github, all the code which is under the main branch is used by the developer. So, if we are not sure about the code is correct or verified then we should not merge the code with the main branch

  • Command to create a new branch

    git branch branch_name

  • Command to shift head from main to a new branch

    git checkout branch_name

  • How to merge the branch with the main

    git branch merge main

Below is the further references:

GitHub Notes 1

GitHub Notes 2

GitHub Notes 3

Β