To avoid getting into this sort of trouble one can expand on the git merge --abort
approach and create a separate test branch before merging.
Case: You have a topic branch, it wasn't merged because you got distracted/something came up/you know but it is (or was) ready.
Now is it possible to merge this into master?
Work in a test branch to estimate / find a solution, then abandon the test branch and apply the solution in the topic branch.
# Checkout the topic branch
git checkout topic-branch-1
# Create a _test_ branch on top of this
git checkout -b test
# Attempt to merge master
git merge master
# If it fails you can abandon the merge
git merge --abort
git checkout -
git branch -D test # we don't care about this branch really...
Work on resolving the conflict.
# Checkout the topic branch
git checkout topic-branch-1
# Create a _test_ branch on top of this
git checkout -b test
# Attempt to merge master
git merge master
# resolve conflicts, run it through tests, etc
# then
git commit <conflict-resolving>
# You *could* now even create a separate test branch on top of master
# and see if you are able to merge
git checkout master
git checkout -b master-test
git merge test
Finally checkout the topic branch again, apply the fix from the test branch and continue with the PR.
Lastly delete the test and master-test.
Involved? Yes, but it won't mess with my topic or master branch until I'm good and ready.
[rejected] gh-pages -> gh-pages (non-fast-forward)
– Chetabahana