Git Merging and learn how to merge in git

Git Merging

Though Git Branching is a powerful feature to branch the development work without changing the mainline, to add the features from one branch to another we need of this Git Merging, yet another powerful feature. Git Merging feature by merging the one development work of a branch to another branch it currently resides. This post help you to understand, how to git merge works and merge files in git from one branch to another.

Git Merge working

In Git Merging, we used the main command

  • $ git merge

The merge command will merge the given name branch to the current branch. When a merge command is given, a new snapshot is created in the current branch. Now, the pointer points to both previous snapshots of the current branch and another branch.

Here, we continue from the previous Git branching post(if not read it Git Branching). Assume, you’re currently in the ‘test’ branch. You made some improvements to the ‘test’ branch. Now, you want to add those features to the ‘master’ branches. First, navigate to the ‘master’ branch by the following command

$ git checkout master

Now, you moved to the ‘master’ branch. To merge the files to the ‘master’ branch from the ‘test’, type

$ git merge test

After this, it shows the following image

git-merge-work

The updating of checksums shows in the first line, the type of merge in the second line, the files merged and altered in next and changes in the last.

git-merging

The illustration describes that snapshot s6 from the ‘test’ branch is merged to the s5 ‘master’ branch as s7 snapshot. Now, the pointer heads to s5(master) and s6(test). This is how the basically merging works in git.

Problems with merging

When we try to merge a file, which is altered in both branches, it makes some conflicts with the merging and it shows git asks us to clear the conflict first. This looks like

merge-conflict

Here, I altered a Readme.md files both in master and test branches. When I try to merge it, it shows the ‘CONFLICT’ message.

Learn how to resolve this merge conflicts -> Go.

Learn how to branch in git -> Go.
Click here for Git archives.

To view official git documentation please visit git docs.

As I’m new to the blog, I trying to improve the contents daily. Please support it through comments.

 900 total views,  1 views today

Leave a Reply

Your email address will not be published. Required fields are marked *