I have rebased a branch locally which was already pushed.
Git is advising that my branch and remote have diverged and that:
"and have 109 and 73 different commits each, respectively"
Will pushing my branch resolve this - i.e. is this to be expected after a rebase?
This can be properly resolved by committing changes from the merge first by git commit , then adding and committing the unstaged changes as usual (e.g. by git commit -a ). Show activity on this post. Replace 123 with number of commits your branch has diverged from origin.
A branch in git is a series of interrelated commits. If two branches follow a non-linear path then they diverge each other.
Git Rebase Instead of a Merge As you may already know, Git allows for the creation of multiple branches that diverge from a “master” branch. On these divergent branches, multiple changes, and iterations and commits may be made. Then those changes can be integrated into the master timeline.
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.
When you rebase a branch, you have to rewrite the commits for any commit which is above the commits in the branch onto which you are rebasing. This is because one of the properties of a commit is its parent (or parents). When you rebase, you're changing the parent of the oldest local commit on your branch - and thus changing the commit hashes of all of your local commits, since this change bubbles up through the commits transitively.
Since you'd already pushed the branch, you should have merged in the source branch, rather than rebasing against it. It is possible to "force push" your new branch (using the -f
flag), but a normal push won't work, because the integrity of the branches history will be disturbed. If you are collaborating with others on this branch, force pushing is a bad idea, as it will cause other collaborators to become very confused when their history suddenly doesn't match.
TL;DR - If you're not collaborating, push the branch using push -f. If you are, reset the branch to the previous state, and merge in the source branch, instead.
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