Git : What, Why and How..

2.2 Learning Git | Hasura Internship

By Jason Long ( [CC BY 3.0 (], via Wikimedia Commons

Step 1 : What is version control and git?

For this internship, our two-member team will be making a website for the startup “Green Strips”. If we want to edit the same file without disrupting each other’s work, we will have to:

  • Lock a file while working on it so that the other person cannot edit it at the same time.
  • Share the files to a common location so that both have access to the latest version.

Besides being error prone and risky, this file locking scheme would mean big hold ups as the team size increases. Many developers would want to work concurrently on the same files, be able to track code edits and roll back to a previous version if something goes wrong.

This is where version control comes in.

Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.

Version control can be of three kinds:

Local , Centralized and Distributed version control. [Source: The Pro Git Book]
  • Local version control system (VCS): Keeping version history on the local machine itself.
  • Centralized version control system (CVCS): Keeping version history on a single server from where a number of clients can check out files.
  • Distributed version control system (DVCS): When clients check out files from the remote repository, complete version history is also backed up locally.

Git is an example of a mature, open source DVCS originally developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel. Check this for a short history of its development.

Step 2 : Why use git?

  1. Distributed Development: Git gives each developer a local copy of the entire repository along with the full development history.
  2. Data stored as snapshots: Every time there is a commit, git takes a snapshot of the file contents at that moment and saves a reference to it.
Time required for various operations [Source: Git Tower blog ]

3. Local Operations:With locally stored version history, most git commands appear almost instantaneous and does not require connections to remote servers.

4. Security and integrity: All objects in the Git repository are secured with a cryptographically secure hashing algorithm called SHA-1.This ensures the change history is fully traceable and protected against accidental or malicious alteration.

5. Flexibility: Git is scalable and compatible with existing protocols and systems. Repositories can be published over HTTP, FTP or using SSH. CVS repositories can also be used with git-svn.

6. Parallel workflow: With branching and merging git allows simultaneous development of different features along different branches.

Step 3 : How to use git?

Navigate to your working directory and open Git Bash
Git Workflow
  1. Open git bash terminal from your folder by right clicking and choosing ‘Git Bash Here’.
  2. To initialize git: git init
  3. To add files to the staging area so that git can track changes : git add <filename>
  4. To see the current status of files: git status
  5. To commit changes: git commit -m "Your commit message"
  6. To view commit history: git log
  7. To create a local working copy of a remote repository: git clone <url>
  8. To add a new remote Git repository: git remote add <repo-name> <url>
  9. To share local branch on remote server git push [remote-name] [branch-name] only if you have write access and if nobody has pushed in the meantime.
  10. To get data from your remote projects:git fetch <remote-name> and then merge it with your local branch by git merge <branch>
  11. If our local branch is tracking the remote repository we can directly use git pull <remote-name> <branch-name>
  12. To create and change to a new branch: git checkout -b <branch-name>
  13. To delete branch: git branch -d <branch-name>
  14. To check differences with the last commit : git diff HEAD
  15. To tag your code versions: git tag <version> <commit-id>

Try out these commands online at:

Additional Free Resources:

In case you ever mess up while using git, check out

Show your support

Clapping shows how much you appreciated Green Strips’s story.