by BehindJava

What is Git Merge

Home » interview » What is Git Merge

In this tutorial, we are going to learn about git merge in detail.

What Is Git Merge?

Git merge is a command that allows you to merge branches from Git. Merging is a common practice for developers. Whether branches are created for testing, bug fixes, or other reasons, merging commits changes to another branch. It takes the contents of a source branch and integrates it with a target branch.

Git Merging

Merging of branches is done based on the time stamp of the commits.

  1. Create a few commits on master.

    touch f1
    git add .
    git commit -m "a"
    touch f2
    git add .
    git commit -m "b"
  2. Check the commit history.

    git log --oneline
  3. Create a branch and create few commits on it.

    git checkout -b test
    touch f3
    git add .
    git commit -m "c"
    touch f4
    git add .
    git commit -m "d
  4. Check the commit history.

    git log --oneline
  5. Move to master and create few more commits.

    git checkout master
    touch f5
    git add .
    git commit -m "e"
    touch f6
    git add .
    git commit -m "f"
  6. Check the commit history.

    git log --oneline
  7. To merge the test with master.

    git merge test
  8. Check the commit history.

    git log --oneline