Let’s Give a Shot on Git and Git Flow

Imagine you are working on a project with a team of 5/6 members. And you are not using git. How devastating that would be? Maybe one of you has to code first then another one will work on the same code base. Or maybe you guys will use a Pendrive or portable hard disc. Or whatever the way is without git. How slow the development process would have been. How devastating the situations would have been. Please don’t imagine. You might get hurt. I’m writing this article for the newbies who started their software development journey recently. I will talk about git and git-flow today.

Git And Github

Imagine you are developing a software in your laptop. And you have a cat or a dog. Or a bad girlfriend with whom you have just fought last night. While developing the software you thought of having a coffee. So you went to the kitchen. In the meantime your girlfriend or cat or dog accidentally/intentionally (for your girlfriend) deleted some files and some lines of code and turned off the laptop.  Well, how can a dog turn off a laptop? He just pressed the wrong button accidentally. Whatever it is. A bad thing happened while you went to your kitchen to make a coffee. When you will return you will just have to cry. Here comes git for this kind of situation. It tracks the changes in your local machine. So, install git and problem solved.

git flow

Now you are using git for a couple of days and your project becomes very serious. Your cat or dog or even your girlfriend can’t destroy your project. But suddenly some kind of natural hazard destroyed your laptop. How can git help you then? Well, here comes GitHub or GitLab or bitbucket. There is just a remote machine to keep track of your changes so that no natural hazard can destroy your serious project.

And what is Gitflow Workflow?

Well, as the Atlassian’s said,

“Gitflow Workflow is a Git workflow design that was first published and made popular by Vincent Driessen at nvie. The Gitflow Workflow defines a strict branching model designed around the project release. This provides a robust framework for managing larger projects.

Gitflow is ideally suited for projects that have a scheduled release cycle. This workflow doesn’t add any new concepts or commands beyond what’s required for the Feature Branch Workflow. Instead, it assigns very specific roles to different branches and defines how and when they should interact. In addition to feature branches, it uses individual branches for preparing, maintaining, and recording releases. Of course, you also get to leverage all the benefits of the Feature Branch Workflow: pull requests, isolated experiments, and more efficient collaboration.”

Let’s learn how to use git with Github

First of all, we need to install git in your local machine. We will do that in ubuntu. If you are in windows then leave or and install ubuntu and come back. Otherwise, I’m not for you.

Step 1 — Update Default Package

Got to your terminal and update default packages.

sudo apt update

Step 2 — Install Git

Now install git in your local machine

sudo apt install git

Step 3 — Confirm Successful Installation

You can confirm that you have installed Git correctly by running this command and receiving output similar to the following:

git --version


git version 2.17.1

Step 4 — Config

Now that you have Git installed and to prevent warnings, you should configure it with your information

git config --global user.name "Your Name"

git config --global user.email "youremail@domain.com"

Step 5 — Commit and Push

Now go to your Github account and create a new repo. After that, get back to your local machine and project that you wanted to be in Github. Inside the root directory of your desired project, run the below commands.

First, initialize your git repository locally.

git init

Add all the changes.

git add .

Commit them with a message.

git commit -m "first commit"

Add remote origin and push them into the master branch of the newly created Github repository.

git remote add origin {get this url from your github}
git push -u origin master

Let’s learn git-flow

To use git-flow, first, we need to install it.

sudo apt-get install git-flow

Now you can create another repo in GitHub for this test purpose. And in your local repo, to init git-flow, run this command below.

git flow init

Development of new features starting from the ‘develop’ branch. Start developing a new feature with the below command.

git flow feature start feature_name

This will create a new branch from the develop branch.

To finish the development of a feature run the below command.

git flow feature finish feature_name

This command will do 3 tasks. First, it will merge the branch into develop branch and it will delete the branch and switch back to develop branch.

Then you can continue developing and merging new features by creating a new branch again and again.

Ok, What if you need to pull a published feature? Which may have been done by one of your co-workers,

git flow feature pull origin feature_name

And to track a feature on origin,

git flow feature track feature_name

To start a release, use the git-flow release command. It creates a release branch created from the ‘develop’ branch.

git flow release start RELEASE [BASE]

It’s wise to publish the release branch after creating it to allow release commits by other developers. Do it similar to feature publishing with the command:

git flow release publish RELEASE

Now the most important part. Finishing a release. Finishing a release will perform these tasks:

  • Merges the release branch back into ‘master’
  • Tags the release with its name
  • Back-merges the release into ‘develop’
  • Removes the release branch

Then run this command to finish and push your tag.

git flow release finish RELEASE
git push origin --tags

Now remember one thing, always try to sync with develop-branch. You should always pull from develop-branch whenever your co-workers finish a new feature.

It’s time we should talk about the hotfix. Imagine its Friday night. And you are getting prepared to go home but your project manager gave you an issue from production. You can’t blame you manager. Because the fault is yours. What you will then? Start a hotfix from the master-branch.

git flow hotfix start VERSION [BASENAME]

Then fix the issue within a glance with the vibe of lightening. And then finish the hotfix.

git flow hotfix finish VERSION

That’s how you will save the day like a hero. Practice this way by creating your own project or make fun with your team building hobby project maintaining the git-flow.