17 Version Control System – GIT

Mr. Hardik Joshi

epgp books

 

Introduction

 

Programmers develop software on daily basis. Every day, they add more code to the existing program. So, the software keeps on evolving. To manage the changes made in the software on periodic basis, version control systems were developed. Imagine there is a team of developers working on the same project. When each programmer starts submitting their code, it will become difficult to track who submitted the code and when. In case, if we want to rollback to the earlier version, it will be difficult in simple file based system. The version control system manages the changes made to system and if need arises, restores to some previous recall point. Although there are many version control system like CVS, Subversion, Perforce, Bazaar, and so on, GIT is an open source distributed version control system, we will study the GIT software in the module.

Version Control System

 

Version control system records changes to a file or set of files over time so that we can recall specific versions later on when required. A version control system keeps track of all changes made to a project. It allows many users to work in large teams on very complex projects while minimizing the conflicts between changes. Version control systems are necessary while developing software in teams. Each team member can have their own working copy of the project code without interfering with other developer’s copies or the main trunk.

 

Figure 1: Version control system – Local, Centralized & Distributed(Image source: https://git-scm.com/book/en/v2)

 

Few widely used version control systems include CVS (Concurrent Versions System), SVN (Apache Subversion), Git, etc. CVS is mostly a legacy system; SVN is a centralized system while Git is a decentralized system. Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. There can be multiple servers that can act as repositories, but each copy on each developer’s own system is also a complete revision copy. Each team member can have their own working copy of the project code without interfering with other developer’s copies or the main trunk.

 

Overview of GIT

 

Development of Git was initiated by Linus Torvalds in 2005. Git is written in C, Shell, Perl, Tcl and Python, Git supports OS like Linux, Windows, MacOS. Git is released under GNU GPLv2 and GNU LGPL License. GitHub is a web-based Git or version control repository and Internet hosting service. It offers all of the distributed version control and source code management (SCM) functionality of Git as well as adding its own features. It provides access control and several collaboration features such as bug tracking, feature requests, task management, and wikis for every project.

 

Installation of GIT

 

GIT software is available for various platforms like Linux, MacOS, Windows and Solaris. Let us explore how to install GIT in our system.

 

Figure 1: git software installation

 

For Windows, GIT can be downloaded from the website http://git-scm.com/downloads, The software is an installer file which can be installed in windows. Git has its own bash prompt and a command prompt. To install GIT in Linux, we must type the following commands at command prompt for Ubuntu based distribution and Red Hat based distributions respectively:

 

We must enter our name and email address (highlighted in red color) while configuring git. The above command will create a single repository on our local system.

 

GitHub.com

 

GitHub is a web-based Git or version control repository and Internet hosting service. It offers all of the distributed version control and source code management (SCM) functionality of git. It provides access control and several collaboration features such as bug tracking, feature requests, task management, and wikis for every project. GitHub.com allows us to share our open source code with others by creating a repository over internet. It is a hosting service, where it is free for open source software, however, those who want to create private repositories that is not visisble to others need to pay to maintain their private repository.

 

Github allows to:

  • Share our repositories with others
  • Access other users repositories
  • Store remote copies of our repositories (on Github server) in case if something goes wrong

Figure 2: Using local and remote repository

 

Figure 3: Screen after signing up at GitHub.com

Figure 4: Creation of repository at GitHub.com

 

Figure 4 illustrates creation of repository on GitHub.com. We are creating a public repository with the name “myfirsrepo”. The login name used is epgpathshalademo. We can initialize the repository from this screen.

Figure 5: Repositories in our login at GitHub.com

 

As demonstrated in figure 5, we can see that there are 3 different repositories, these repositories are:

  • myfirstrepo (created by us)
  • gir (forked repository)
  • Jung (forked repository)

Using GitHub.com, we can add other repository in our account. This process is known as forking. So, when we click on fork icon available on others repository, the code will be copied in our login.

 

Creating a local repository and synchronizing it with GitHub.com

 

In this section, let us create a local repository on our machine and we will see how to synchronize our local repository with the public repository available at GitHub.com.

Using the above mentioned commands, we are creating a local repository and connecting it with the GitHub.com repository. The steps are:

 

1) Create a directory with the name of repository name

2) Change to the newly created directory

3) Initialize the repository (this will create a .git hidden direcroty)

4) By issuing the command $git remote add origin <pathname>, we are connecting our local repository with the remote repository.

Now let us see how to push the files to remote repository. Suppose that our source code is residing in some folder, we change directory to that folder and issue the following commands:

 

The first command in above code will add all files to local git repository, then after committing the repository, we push the files to remote repository using git push command. The following figure shows the output of performing push command, the screen shot is of GitHub.com website where it shows that our c programs and a header file have been pushed to remote repository.

 

Figure 6: Source code pushed to Remote Repository

 

Cloning / Downloading the repository

 

Suppose we want to download an entire project from the website GitHub.com, we can either use the GUI to download from the website or we can issue the clone command from command prompt.

 

Figure 7: Downloading a repository from GitHub.com

 

The syntax to download a repository from GitHub.com and the command to download the repository indicated in figure is as shown below:

 

 

The website GitHub.com has various open source projects hosted on it. Many students upload their assignments, few of them upload books, sample code, etc. on GitHub.com website.

Let us summarize what we have learnt in this module:

  • Understood the meaning of version control system
  • Got an overview of Git software
  • How to upload source code and download source code using GitHub.com
you can view video on Version Control System – GIT

    References:

  • Eric. Pidoux. 2014. Git Best Practices Guide., Packt Publishing.
  • Donald Wexler. Getting Started with GIT,
  • Git : Distributed Version Control :Fundamentals and Workflows, Brainy Software.
  • Aske. Olsson and Rasmus. Voss. 2014. Git version control cookbook, Packt Publishing.
  • Emma Jane Hogbin Westby. Git for teams,
  • Jon. Loeliger and Matthew (Matthew J… McCullough. 2012. Version control with Git,
  • Ravishankar. Somasundaram. 2013. Git : version control for everyone : the non-coder’s guide for everyday version control for increased efficiency and productivity : beginner’s guide, Packt Publishing.
  • Shaumik Daityari. Jump start Git,
  • Scott Chacon and Ben Straub. Pro Git, Apress (Download: https://git-scm.com/book/en/v2)
  • Github Website: www.github.com