Understanding Version Control Systems through Git

Damsak Bandara
7 min readMay 13, 2021

Version Control Systems (VCS)

Definition-

“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 —

  • Enables multiple people to work simultaneously.
  • 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. Repository: A centralized storage with the revision history of all related and specified files.
  2. Workspace: Refers to the copies of the files in the local machine of the user. Also known as working copy.
  3. 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

Git is the most popular Version Control system available in the market. It is a distributed version control system. Git is also free and Open-source. Git provides various functionalities for branching, merging, and rewriting repository history. This is the main factor that increased Git’s popularity. Github is a web-based platform used for version controlling with the help of Git.

GIT Vs GitHub

There are some key differences between Git and 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. Online file editing.
  2. Desktop GUI tool for managing GitHub repositories.
  3. Branch protection tules.
  4. Fork capabilities.
  5. Email notifications and alerts.
  6. Increased Security.
  7. 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?

We can use Github from the GitHub Desktop application or by using the command line.

Cloning a Repository

The repository we create from Github exists in a remote server. By the process of cloning, we can create a copy of that repository in our local machine. Git provides the necessary functionalities to perform the syncing of files between these to repositories. There are 2 main ways to clone 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

This is the primary command used to get the content from a remote repository. After downloading the required content, this command will merge those changes to the local repository according to the guidelines.

$ git pull <remote>

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

Git Push

Command used to send the updated content of the local repository to the remote repository. The push command overrides the content in the remote repository.

$ 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

Command used to add the changes in the current working directory to the staging area. These are the files that you hope to send to the remote repository in the next commit.

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

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

Git Commit

Command used to capture a snapshot of the currently staged changes. Developers have the capability to commit to different branches. The best practice is to always add a message with the commit. This message should clearly specify the changes made to the files.

$ git commit -m <message>

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

Git Revert

This is a command used to change history in Git. This will look at the changes done in a specific commit and then apply the inverse of those changes. It is basically an “undo commit” command.

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.

--

--