News

New paper! in the American Naturalist

Wednesday, February 7, 2024

Git: how to handle divergent branches

$ git pull origin master
--> oops! hint: You have divergent branches and need to specify how to reconcile them.
Divergent branches occur when both master branch and your feature branch (your origin, i.e. remote branch, or any other branch that one created) have accumulated new commits. (so the repository graph looks like Y shape).

[Option 1: recommended when the other branch your getting changes from is shared with others] 

You can then do $ git pull --no-rebase origin master
This will merge the two branches at the end, incorporating commits from both branches, and bring master to the tip (merged point).

[Option 2: recommended when you are handling two branches that are not shared with others] 

In contrast, $ git pull --rebase origin master
This will rewrite the commit history and merge two branches such that there is only one sequence of commit histories. A merit is a cleaner commit history, but should be used with a caution when others are involved, as reverting is harder with rebasing than merging.


These articles a good description of the difference between merge and rebase: link and link2