Git 101 and its day to day usage: Part 2

Abhinav Dhasmana
Feb 22, 2017 · 3 min read

This is a part two of a series of blog where I am planning to capture on how we provide technical apprenticeship to new college graduates that intern with us. Part 1 can be found here


If you noticed in part 1, everything was about working with git changes that are local on your box. This post will cover some common scenarios which you might encounter.

Scenario 1: You are starting a new feature/bug fix.

Make sure your master is updated. This can avoid conflicts and make merging easier.

Simply do a git pull.

Initial state

After git pull

Now, you can create a new branch from master

Scenario 2: You have completed your work on your branch and want to make this change to master.

You can run git merge feature-branch on a master branch

There can be two scenarios here:

2.1 When no commit has been made to master since you created your own branch.

After merge, the git tree would look like

This merge is known as fast forward merge as all git had to do was to move its head from 2 to 4.

2.2 When commit has been made to master since you created your own branch.

In a scenario like this, git creates a new commit, a merge commit, and points your master to it. This is known as 3-way merge

In the above diagram, commit 6 is created by git. In this scenario, we can enter into a situation where we have a conflict. You can get a message like

To solve this, you would have to do the following steps.

Scenario 3: There is more than one person working on your branch. You want to incorporate those changes before raising a pull request

This scenario is no different than scenario 1. Just run git pull origin feature-branchand you are good.

Scenario 4: You want to incorporate changes from another branch

There are scenarios where you would like to take a change from another branch on which you would like to develop upon.

Now, you want changes in commit 4 and build on top of it. You can run the following commands to make this happen

After running this, your git tree will look like this.

Note that the commit after 4 are 3' and 5' and not 3 and 5 as rebase rewrites the commit history.

Missed anything? Let me know in comments and I’ll add it.

Thanks to Mahesh Haldar.

Abhinav Dhasmana

Written by

Tech Architect at mfine. Ex-McKinsey/Microsoft/Slideshare/SAP, Tech Enthusiast, Passionate about India. Opinions are mine