Merging with git

a minute read

Git merge lets you bring the changes from one branch, on to the other. Merge replays the changes in a branch on top another, starting from the commit where the two branches last diverged. Lets take for instance 2 different branches.

 –  staging

1
2
3
4
5
commit A

commit B

commit C

 live

1
2
3
4
5
6
7
commit A

commit I

commit J

commit K

to merge the the staging branch on to the live branch, you need to:

1
2
3
git checkout live

git merge staging

This will replay the changes made in the staging branch, on top of the live branch at the point where their history last diverged. In this example, both branches diverged from commit A and staging will apply all of its commit snapshots on top of the live branch til the most recent staging snapshot, which is commit C.

Merge will record this replay in a brand new commit along, with the names of the two parent commits and the change log.

git rebase vs merge

Rebasing for a fact creates a cleaner history than merge. The history of a rebased branch consists of a series of linear commits even though the actual work may have happened in parallel. The end result of a merge and rebase will always be the same as they both point to exactly the same diffs, but only the recorded history of snapshots being the difference. Merge always create an additional commit on top of the existing snapshots being brought forward, and also its replay of snapshots on the target branch is not linear.

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

Comments:

No comments

Related Posts:

GIT is a revision control system that allows multiple contributors to work on same projects/files. Is also useful if you have more servers/vms/workstation that you manage and you want to deploy “recipes”/scripts/configurations on them. With GIT, you work local...
Git makes working on a project flexible by allowing teams to work in parallel and concurrently. When a team’s work is done, they can bring their work on to the main public branch either by rebasing it or merging it.
Git refspecs specifies the patterns for references on the remote side and the locally tracked branch. When you create a new repository and add a new remote to it i.e git remote add origin url
Git Commands List