I'm getting in problems with git.
I wanted to rebase a branch hotfix
over master
local and remote, both, so this is what I did.
git checkout hotfix
git pull hotfix #just getting someone changes
git fetch origin master
git rebase origin/master
After a long time resolving conflicts and rebuilding project I have it working ok, so I have to upload the changes to the remote branch.
git push origin hotfix
And this is waht git thinks:
$ git push origin login2
To https://[email protected]/***/***.git
! [rejected] hotfix -> hotfix (non-fast-forward)
error: failed to push some refs to 'https://[email protected]/***/***.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
I have tried:
git pull --rebase
But this gives same conflicts like before the other rebase and it shoudln't.
I Know I always can do:
git push -f
But I would preffer to avoid the forced push because I work with another person. I would like to know what I did wrong. I thought that was the way.
PD. I have run gitk
and it seems there is no reference to the remote origin/hotfix
, just the local hotfix
appears.
Thank you!
Edit: I guess that when I did the rebase the last commit of the branch change to apply the rebase changes, that was the reason why it had another sha1 commit id. I did a pull overriding my local files.
git pull --strategy=ours origin hotfix
One thing you need to know about rebase is:
Git will change the SHA hashes of every commit not part of the new base branch.
This means there will always be a conflict with the upstream branch after you rebase your local branch and the only way around it is to force push to your upstream.
A common practice is to not rebase commits that have been pushed to upstream. Rebasing is still okay if there is only one person working on a branch.
In this case, you don't have an option but to do a force push. In the future it is advisable to keep the working branch for you and your collaborator separate and have a mix of rebase and merge strategies to share your work
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