I had a local topic branch based off a remote branch on the git repo:
1 - 2 - 4 - 5 - 9 - 11 master
\
3 - 6 - 8 - 12 remote branch
\
7 - 10 my topic
The remote branch was recently rebased off master:
1 - 2 - 4 - 5 - 9 - 11 master
\
? 3' - 6' - 8' - 12' remote branch
\
7 - 10 my topic
I would like to rebase my topic branch off the head of the remote branch so that I can eventually merge my changes back into the remote. However, because the hash of the parent commit has changed, trying a simple
$ git rebase origin/remote_branch
results in a number of conflicts in files I've never touched.
Is there anything I can do to clean up these branches?
For a rebase, you just need to resolve the conflicts in the index and then git rebase --continue . For a merge, you need to make the commit ( git commit ), but the fact that it's a merge will be remembered and a suitable default commit message will be supplied for you to edit.
From a content perspective, rebasing is changing the base of your branch from one commit to another making it appear as if you'd created your branch from a different commit. Internally, Git accomplishes this by creating new commits and applying them to the specified base.
Because of the rebase, our local branch is the leading one. This has all the latest bits from our target branch and includes all of our changes. To get it all back into sync, we need to do a force push. With a force push we simply push all our local changes and overwrite whatever is on the remote branch.
This one is easy: If you're not pushing, you can only affect local things. If only local branch is rebased, should I commit to origin again after the rebase? This one has an embedded misconception. When you make commits, you're still only affecting local things.
Simply rebasing on origin/remote_branch
is confusing for git because it tries to rebase outdated commits on the tip of remote_branch, which leads to duplicate commits and conflicts.
Instead you must plug off and on, to the new point commit related to the sixth one, using the --onto
option
git rebase --onto <6'-SHA> <6-SHA> my-topic
<6'-SHA>
and <6-SHA>
are respectively the new and old ids of the commit where my-topic
was created.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With