It's quite common to open up a pull request on GitHub and be confronted with the message This branch has conflicts that must be resolved
. This situation arises when you create a feature branch on an older commit from the master branch. Maybe you forgot to run git pull master
before git checkout -b geocoding_vignette
or maybe a collaborator changed some of the same files on GitHub while you've been working on new things. There are many ways to fix this. One is using the Web Editor build into GitHub and fixing conflicts by hand. This works great if there are not too many conflicts.
Another technique is to rebase your pull request onto the master branch (Move your additional commits on top of the most recent master commit). This is conceptually clean, but sometimes confusing in practice to do cleanly. This example walks through the process where you want to do a rebase, and resolve conflicts by overwriting whatever is on the master branch with changes from your feature branch. Here are some helpful articles to understand more about this technique https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request, https://howchoo.com/g/njcyntcxmwq/git-merge-conflicts-rebase-ours-theirs.
git checkout master
git pull
git status
Output:
On branch master
Your branch is up to date with 'origin/master'.
gh pr checkout 66
Output:
From https://github.com/DSSG-eiCompare/eiCompare
* [new branch] geocoding_vignette -> origin/geocoding_vignette
Switched to a new branch 'geocoding_vignette'
git rebase master
Output:
First, rewinding head to replay your work on top of it...
Auto-merging vignettes/geocoding.Rmd
CONFLICT (content): Merge conflict in vignettes/geocoding.Rmd
error: Failed to merge in the changes.
git checkout vignettes/geocoding.Rmd --theirs
git add vignettes/geocoding.Rmd
git rebase --continue
git status
Output:
On branch geocoding_vignette
Your branch and 'origin/geocoding_vignette' have diverged,
and have 125 and 7 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
git push -f
This was helpful, thank you.