Understanding Version Control Systems through Git

Version Control Systems (VCS)

“A Version Control System is a software tool that helps in recording changes made to files by keeping track of modifications done to the code.”

As we all know, a software product is developed by several Engineers. A version control system helps these developers to track and manage changes done to the software code. So they can simultaneously work on the same project. In a VCS each of the developers can get a copy and edit it without interfering with another person's work. This is the primary goal of a VCS.

Impact of VCS on a software product

Functionalities —

  • Temporary or partial edits by one person do not interfere with another.
  • Integrates work done simultaneously by different members.
  • Easily access historical versions of the project(Rollback easily).
  • Easily Get information about a file( Where, when, and who edited it)

There are many other functionalities.

Popular terms in Version Control systems.

  1. Workspace: Refers to the copies of the files in the local machine of the user. Also known as working copy.
  2. Branches: Known as the lines of development. There are 5 main types of branches.
  • Main Branch
  • Feature Branch
  • Release Branch
  • Hotfix Branch
  • Develop Branch

4. Tag: Represent a particular snapshot of a project at a given time.

5. Pull / Update: Update the local working copy with the latest changes through the main branch or another local space.

6. Commit/Check-In: Store a change in the central Version Control storage.

7. Push: Used to send commits to the determined central repository.

8. Conflict: Situation where 2 developers try to commit changes in the same region of the same file.

9. Merge: Combining changes in different working copies to the same file in the repository.

There are 2 main types of Version Control Systems.

1. Distributed Version Control Systems

In a Distributed Version Control System each and every user has a dedicated local repository and a working copy. The committed changes are inside the local repository until they are pushed to the main central repository. Other members of the project cannot see these changes in the local repository. There are several key advantages of Distributed Version Control Systems.

  • Users can work offline.
  • Increase developer productivity.
  • Eliminate reliance on a single backup.

Git, Mercurial, and Bazaar are the 3 most popular Distributed Version Control Systems in the market.

2. Centralized Version Control Systems

A Centralized Version Control System consists of one central repository. The users have a separate working copy. All the commits are visible to other co-workers when they update their copy. Developers do not need to keep multiple copies of files in their local machines because the version control system directly communicates with the central main repository.

Subversion, CVS, and Perforce are some of the most commonly used Centralized version Control Systems.


GIT Vs GitHub

  • GIT is installed locally where GITHUB is hosted in the cloud.
  • GIT focuses on version controlling and code sharing. GITHUB focuses on hosting the centralized source code.
  • GIT is primarily a command-line tool where GITHUB is administered through the web.
  • GIT has no features for user management. GITHUB contains built-in user management.
  • GIT is Open Source and Licensed. Github contains free and pay-for-use tiers.

GIT is a tool that can be used without the help of cloud hosting services such as GitHub, GitLab. But most enterprises need various services and functionalities integrated into their version control systems like Progress tracking, CI servers, etc. Git doesn't provide them. Furthermore, Git does not provide any authentication mechanisms for the repository.

Third-party vendors such as GitHub, GitLab, Atlassian, provide these functionalities. They built these services around Git and make those services available through a cloud-based platform.

Functionalities provided by Github

  1. Desktop GUI tool for managing GitHub repositories.
  2. Branch protection tules.
  3. Fork capabilities.
  4. Email notifications and alerts.
  5. Increased Security.
  6. Project insights related to traffic, code commie frequency, etc.

These are some of the features provided by Github and not by GIT.

How to use Git?

Cloning a Repository

  1. Clone a repository with the help of Command-Line.

Navigate to the GitHub repository and click the “Clone with HTTPS” button under the section “Code”. This can also be done with SSH. For the sake of simplicity, let’s stick to the first method. After copying the required URL, navigate to the local machine’s home directory where you hope to clone the repository and open Git Bash. Then enter the following command.

$ git clone <Copied URL from the Github Repository>

This will create a local copy of the selected repository.

2. Clone a repository with the help of GitHub Desktop

Navigate to the GitHub repository and click the “Open with Github Desktop” button under the section “Code”. This will open the Github desktop application and following the prompted instructions will clone to the repository to the local machine without any commands.

Git Branching

This refers to the concept of deviating from the main line of development and continue work in a separate line(branch) without doing any effect on the mainline. This branching mechanism provided by Git is lightweight and nearly instantaneous. Therefore, developers can easily create a new branch and work on it and merge it to the main branch in a later stage of the development.

$ git branch — List down all the branches in the repository.

$ git checkout -b <branchname> — Create and checkout to that branch with the specified name.

$ git merge <branchname> — Merge the “branchname” in the current branch.

Git Pull

$ git pull <remote>

$ git pull - no-commit <remote> — This command will get the remote content but wont create a new merge commit

Git Push

$ git push <remote> < branch>

There are many other git pull and push options. Please refer to the articles in the references section to know more about these commands.

Git Add

$ git add — Stage all the files in the current folder/directory.

$ git add <file name> — Stage a specific File.

Git Commit

$ git commit -m <message>

$ git commit -amend — Replace most recent commit with a new commit.

Git Revert

There are many other Git commands which can be used to deal with Git. Please refer to the first article in the References section to know more about these commands.

Associate Software Engineer at Virtusa