Git & GitHub


Git is a distributed peer-peer version control system.

Each node in the network is a peer.

Users keep entire code and history on their location machines.

Users can make any changes without internet access so it allows users to be offline and working.


GitHub is a hosting service for Git repositories.

You don’t need to use a hosting service like github if all you want is version control — local git is just fine for that.

Remote repositories/hosting are for backup and collaboration.

Most of the version control systems track the differences between files that have changed, where as git tracks snapshot of your project. Other systems call it “Revision” but with git you are tracking the entire workspace, so they use the term snapshot. It is just an alternate term for “Revision”.

Architecture diagram

Common Commands

git status: It lets you see which changes have been staged, which haven’t and which files aren’t being tracked by Git.

git log: shows all commits.

fork: In Github, not Git you can fork a remote repository. This creates a copy of that remote repository as your remote repository in your github account.

git clone: Create a local copy of your remote repository on your computer.

git fetch origin : Git fetch is for fetching all the files from your remote repository into your local repository.

git pull origin master: You can use git pull to pull changes from your remote repository into your workspace. git pull is a combination of git fetch and a get merge into your current workspace.

git branch: Create an exact copy of your master branch.

git checkout <branch>: Switch to the branch by updating the index and the files in the working tree.

git checkout -b: Specifying -b causes a new branch to be created (as if git-branch were called) and then checked out.

git checkout HEAD: copies files from the latest commit to both the staging and the working directory.

git diff: Show changes between the working tree and the index

git diff HEAD: Shows changes in the working tree since your last commit.

git add: Add file contents to the index

git commit -m: Stores the current contents of the index in a new commit along with a message from the user.

git push: Push committed changes into your remote repository.

Pull Request: You do not have permission to push to someone else’s remote repository, but you can send a pull request from your remote repository to theirs. This functions the same as a push, but rather than forcing the other remote repository to make your changes you are requesting them to accept your changes.

Like what you read? Give Amit Chadha a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.