Git & GitHub - The Simple Guide

 Hi Buddy! How are you,

If you are a tech or geeky person then you hear a lot of Git and Github, or if you are seeking to be a part of an open-source contributor then you must have to learn about Git and Github.

So let's start...

What is Git?



  • Git is a version control system(VCS) for tracking changes in computer files and coordinating work on these files among multiple people.
  • It was created by "Linus Torvalds" in 2005, he was also a developer of Linux Kernel which is also a part of the open-source community


  • Git is a distributed version control system, so git does not necessarily rely on a central server to store all the versions of the project's files. Instead, every user "clone" a copy of the repository (a collection of files) and has the full history of the project on their own hard drive.
  • This clone has all the metadata of the original, while the original itself is stored on a self-hosted server or a third-party hosting service like GitHub and GitLab.


Why Use Git? / Benefits : 




  • Undo Mistakes - Availability of roll-back to previous versions.
  • Distributed Development - Single project can be managed by multiple persons.
  • Security - Git is intended specially to keep up the integrity of ASCII text files.
  • Flexibility - It is quite flexible as it offers to support non-linear development workflow.
  • Don't mix things up / Branching  - This means if you are working in multiple features then you can put them in multiple branches.


How to Install Git?

link - Git - Downloads (git-scm.com)

From the above link download the software and install it by clicking on 'next'.


After successful installation of git -

Open cmd in Windows and terminal in Linux, and type --: git version

Now, if you get similar as shown in the below image then "congrats" your device is ready with git.


Now close cmd or terminal!


Move to GitHub :


Here you have to make your account first - by SignUp 

if already have an account on GitHub then login into it and move on.


After login goes to the ' + ' sign and choose - new repo. OR  you can also choose to make new repo from your repositories section.



now you have your empty repo in Github. Let's use this repo now.

Basic Git Commands :

So here first we see syntax as well as working of all the most used git commands -

# Before using these commands I make a new directory in the local repo i.e learnGitRepo.

  • git init -: To initialize a git repository for a new or existing project.
  • git status -: List the files you have changed and those you still need to add or commit.

Step - Now make a file in any language (here I make a python file as Hello.py)
  • git add -: Add one or more files to the staging area.

Now my Hello.py file move to the staging area, I can see this by using git status after git add command.


Note - # Now I make a new file as loops.py  
           # Connect your device to the internet.
  • git commit -m "commit message" -: captures a snapshot of the project's currently staged changes.
  • git commit -am "commit message" -: This command will add your file in the staging area and captures the snapshot of the project currently in the staging area.

# Here I commit the file hello.py

#Now let's put loops.py in the staging area as well. 

  • git log -: It is a utility tool to review or display all the commits in a repository's history.
  • git config --global user.email "email-id" :- To access your Github by providing your email to git bash.
  • git config --global user.name "username" :- To authenticate your Github username.

# Above use your Github email id and username to log in and access your work by git.
  • git rm --cached <file_name> -: To remove files from staging area (To un-stage).

# Here loops.py gets removed from the staging area
  • git branch <branch_name> -: To create a new branch with name as branch_name.  
  • git checkout <branch_name> -: To switch from the current branch to another.
  • git checkout -b <branch_name> -: TO create a new branch and switch to it.

# Above we make a new branch named - dev.
  • git merge <branch_name> -: To merge a branch into the current branch.


  • git clone <URL> -: TO take a repo. from the internet and download it on your computer.
Take Url of your repo from Github.


then use that Url with git clone command, by this you get the repo or project in your local repo.

  • git push -: To push your code from local repo to remote repo.
  • git pull -:  To fetch or download the content from the remote repository (repo.)  and update the content of the local repository.
  • git reset -: It is used to revert back to the older state of the repo.
  1.       git reset --hard <commit>
  2.       git reset --hard origin/master
    • >> To know more about git command use --: git --help

    Git Workflow :

    From the above diagram, you can understand the working flow 
    by way thanks G**gle for this image. 😉

    Git vs GitHub :


    I hope the above material helps you and gives you some basic knowledge of Git and GitHub.

    Now take a break and keep learning! 
    Have a Good Day...

    Comments

    Popular posts from this blog

    The programming language you can opt

    Programming / Coding - The Beginning