DevOps Classroom Series – 15/Dec/2019 – Git Branching


  • Merge is done when changes from one branch has to be brought to other branches.

  • Merges can be of two kinds

    • Fast-Forward:

      • No Extra commit gets created
      • When the Parent branch has no changes and if we try merging child to parent branch
      • Can be skipped
    • Merge:

      • Extra Commit with two parents will be created
      • In all the other cases apart from Fast Forward Preview
  • Lets continue from previous repository created from here

  • Merge the changes from sprint-1 to master.

  • Note that there were no changes in master branch after sprint-1 branch was created, now merging will lead to fast forward

  • Lets merge

# move to the destination branch (master)
git checkout master
git merge sprint-1
  • Create a branch called as sprint-2 from master
git checkout -b sprint-2
  • An Important fix from sprint-1 is done on master.
git checkout master
echo "Updated Docs of Sprint1" >>
git status
git add .
git commit -m "added imp fix"

  • Continue working on sprint-2 branch
git checkout sprint-2
echo "sprint-2" >> src/
echo "sprint-2" >> test/
git status
git add .
git commit -m "features in sprint 2"
  • Now try to merge the changes from sprint-2 to master
git checkout master
git merge sprint-2
  • New commit gets created and HEAD & Master will be pointing to this new commit.

  • Create a new branch called as sprint-3.

git checkout master
git branch sprint-3
git checkout sprint-3


  • Now add some changes for sprint-3 branch
  • Now an important bug fix is done on master, which is required for sprint-3
  • Now to rebase from master onto sprint-3, execute the following commands
git checkout sprint-3
git rebase master


  • Merge Conflicts can happen during

    • merge
    • rebase
    • pull
  • Lets create a child branch from master and call it as poc-qt

git checkout master
git checkout -b poc-qt
  • Now add the following to src/ at the end
working for qt
  • Now master branch has one commit which changes in src/
  • In master branch has the following contents
Sprint 1 Started
testing is in progress
need to add many comments

  • In qt-poc branch has the following contents
Sprint 1 Started
working for qt
  • Conflicts has to be resolved manually.

Viewing Differences

  • To view differences, use git diff
  • Try the following commands
# make local changes on Working tree
git diff

git diff <commit-id-A> <commit-id-B>

git diff <branch-A> <branch-B>

How is git Working

  • Git is internally a very simple content tracker
  • To understand this, lets create a new folder called as understanding-git
mkdir understanding-git
cd understanding-git
git init
  • Now lets get into .git folder and see the contents Preview
  • lets make our first change
mkdir src
touch src/
git add .
git commit -m "Commit-1"
git log


  • Now lets make other change
mkdir test
touch test/
git add .
git commit -m "Commit-2"
git log


  • To understand how git works , we need to understanding Hashing SHA1
  • Git Uses hashing (SHA-1) to calculate commit ids. Commit id is hash of many things.
  • To understand contents of commit
git cat-file -p <commit-id>
  • Lets examine commit-2 contents Preview
  • Take a look at below image Preview

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner