Versioning With GIT

Vikas Verma
3 min readJun 20, 2014

--

Why GIT?

How many times have you cursed yourself when you had to rollback to an older version of codebase for your software or a web application ? Was there a time which left you puzzled as to who changed the code or released the latest update; while working in a team ?

If you are still wondering about all these questions then I guess you haven’t started using GIT, a versioning system made for developers. It is a decentralized versioning system. It is small, fast and really makes merging of codes hassle free.

How to manage Versions on GIT

When you and your team members are working on different or same part of the codebase, versioning of codebase becomes very necessary. It allows developers to work on any part/feature of the codebase without having fear of losing their work or making irrevocable changes to production.

Apart from GIT there some other versioning system too like SVN. Will explain and compare others in my next post. Here we will restrict our focus to GIT; specifically Versioning in GIT.

Below are the two models which can easily be used for reasonably large projects.

A). Feature Branch Model

B). Gitflow Workflow Model

Feature Branch Model

As you can see in the image above that there is a branch called master, this is your production branch. Any Feature development and bug fix happens in isolated branches derived from master and then merged back to master. For Example,

New Feature Development

Development of Feature1 will be done in isolated branch Feature1 derived from master.

Creating new a branch from master

$ git checkout -b Feature1 master$ git push -u 

Develop Feature1 and commit code

$ git add <new-code-file>$ git commit -a -m ‘New feature developed’

Push new feature branch Feature1 to repo

$ git push -u origin Feature1

After completing Feature1 merge this branch to master. Change your branch to master and pull latest version of branch master

$ git checkout master$ git pull origin master

Merge Feature1 to master

$ git merge Feature1$ git push origin master

Bug-Fixing

Bug Fixing is done in similar way by creating a new branch from master. Fix the issue and merge this branch back to master.

Create new branch bug-fix-1

$ git checkout origin master$ git pull origin master$ git checkout -b bug-fix-1 master

Fix the issue and commit the changes

$ git add <new-file-if-any>$ git commit -a -m ‘Bug Number 1 fixed’

Merge bug-fix-1 with master branch

$ git checkout master$ git merge bug-fix-1$ git push origin master

Gitflow Workflow Model

This Model is based on separation of development and production environment. There are 2 main branches in this model:

branch:- master

branch:- develop

At all times master branch contains latest released code for production environment, whereas develop branch contains latest state of development. When code in develop branch reaches stable release point then develop branch is merged in master branch. Following is the process:

New Feature Development

Create new branch Feature1 from develop

$ git checkout -b Feature1 develop$ git push -u 

Develop Feature1 and commit code

$ git add <new-code-file>$ git commit -a -m ‘New feature developed’

Push new feature branch Feature1 to repo

$ git push -u origin Feature1

After completing Feature1 merge this branch to develop. Change your branch to develop and pull latest version of branch develop

$ git checkout develop$ git pull origin develop

Merge Feature1 to develop

$ git merge Feature1$ git push origin develop

Release Version of your code for production environment.

$ git checkout master$ git merge develop$ git tag -a v1.0 -m ‘First Version v1.0’$ git push origin master$ git push —tags

Git takes away a lot of problems ( more than what is explained above ). Though to make best of it you have to follow certain best practices, will surely write about them in my upcoming entries. Please feel free to ask any question or doubt you may have regarding this

--

--