Version Controlling with Git

Hasitha Subhashana
5 min readMay 15, 2021

--

Figure 1: Source: https://www.memedroid.com/

Over the time, web applications, mobile apps, desktop applications or whatever the software systems that were out there in the world got larger and complex. So, it was not easy to develop them straight away. Also, the existing systems needed changes over the time. With such large and complex software systems came the necessity of version controlling systems.

Version controlling systems are a type of software tools that helps a set software team to track and manage changes to the source code.
Version controlling systems keeps track of every modification to the source code in a special kind of database.

So, if a mistake was made or a bug was occurred with a new feature “developers can turn back the clock”. With VCS they can also compare previous version and the current version to fix the mistake or the bug occurred.

But why version controlling ?

  • Team collaboration.
  • Restoring to previous versions if needed.
  • Can understand what happened during the version updates
  • Works as backup.

What are the types of Version Controlling Systems ?

There are 03 types of version controlling systems.

  1. Local Version Control System.
  2. Centralized version control system (CVCS).
  3. Distributed/Decentralized version control system (DVCS).

Local Version Control System

Figure 2 : Source : https://www.w3docs.com/
  • This is the oldest VCS.
  • Everything was local (was store in your computer). Local VCS kept track of changes to the source code.
  • This could not be used for collaborative development.

Centralized Version Control Systems

Figure 3: Source : https://www.w3docs.com/
  • This was better solution than a local VCS.
  • All the changes to source code were tracked in the centralized server. So central server included the history of entire project.
  • Single point of failure is a critical issue in these (If the central server that has the repo goes down nobody can contribute to the project during the downtime).
  • Entire history of the project could be lost if the central database was corrupted.

Distributed Version Control Systems

Figure 4: Source : https://www.w3docs.com/
  • DVCS were introduced to overs come the issues of centralized version control system.
  • With DVCS every developer has a local copy of the repository in their PC. So, they could even work offline and push the changes later.
  • Some of the DVCS used in present are Git, Mercurial, Bazaar or Darcs.
  • This is the approach used widely in the present.

“Even though there are several Distributed Version Control Systems are out there, 72% of the world uses GIT as their Version Control Systems”

Figure 5: Source: www.openhub.ne

So, what is Git ?

  • GIT is the most widely used VSC and it was developed by Linus Torvalds in 2005. (Yes, you are correct this is the guy who created Linux).
  • If you would like to know further details you can visit their official website http://git-scm.com/

Git workflow

First of all, you have to be familiar with the work flow of Git. When you use Git to version control in a project, there are 05 main components in that project.

  1. Remote repository.
  2. Local repository.
  3. Staging area / index.
  4. Working tree / working directory.

States of Git files

Below are the 03 states of a file.

  • Modified
  • Staged
  • Committed

When a file is modified changes can only be seen in the working directory. Then you should stage them to include them in the next commit. After staging all the necessary files , they can be committed with a message that clearly explains what’s in the commit.

We don't want to get things in complicated here. Lets discuss further about workflow and the states of Git files in a upcoming articles.

Basic Git commands

*Master is now referred as Main

git init

  • Turn one of your existing directories to a git repo.

git clone

Note : By default, git clone will set up a local main branch that tracks the remote main branch it was cloned from.

git add

  • Used to stage a change so Git can track the changes to the source code. This also can be used for staging as well.

git commit

  • Records the files in version history

git status

  • Gives a list of files that are waiting to be committed.

git branch

  • Gives a list of all local branches of the current repository.

git pull

  • Fetches updates from the remote server and merger them with working directory

git push

  • Sends the committed changes to the remote repo

We have discussed some basic things about Git in here, but surely let’s further dive into concepts of Git in future articles.

Reference

--

--

Hasitha Subhashana
Hasitha Subhashana

No responses yet