Git: Merge vs Rebase

These two git options do the same thing in different ways: they both bring together code in separate branches.
 

 
Merge uses merge commits (which have two parent commits). Since it’s common to merge main into a feature branch multiple times during longer developments, this can make the history more complex than it needs to be.
 
Rebase rewrites commits in one branch to be commits in another branch. I assume this means calculating new diffs under the covers, and therefore generating new commit IDs.
 
Rebase can also be used to rewrite the commit history in a branch without moving commits between branches – potentially useful for a tidy-up
 
So the utility of one over the other probably depends on how important individual commits are in history? For personal projects where I might branch and merge during development, keep the history clean-ish, but sometimes need to write and merge thing B before completing thing A, rebase could be quite useful: should deliver a clean, linear history. In large groups, maybe merge is still better? Try to limit the number of merge commits so that the features are more obvious?
 
This was good on the topic: https://www.atlassian.com/git/tutorials/merging-vs-rebasing

Leave a Reply

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

I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.More information on Akismet and GDPR.