When You Have Two Branches in a Git Repo, How Can You Reconcile the Differences When You Merge Them?

Problem scenario
When you have created a branch of a Git repo, and there have been changes made to the master branch and this second branch you created, what are your options?

Possible Solution #1. You can merge the two branches (e.g., with a pull request). One branch will prevail if there are any conflicts. You can select which branch to prevail with GitLab, Atlassian Bitbucket, or regular Git.

Possible Solution #2. You can use git rebase. This will apply your second branch to the current state of the upstream master branch. git rebase makes the master branch as the main base. If no changes happened to the master branch since the second branch was created, using git rebase in this scenario would have the same effect as merging the second branch with the master branch with the option to have the conflicts be resolved with the second branch's changes prevailing. In all instances, the branch you are working in will have its changes preserved after a git rebase.

Leave a comment

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