I'm trying to force push a rebase of a feature branch to a remote repository. To be a bit safer, I'm trying to use --force-with-lease
to make sure no other changes have happened in the branch since I last fetched it.
This is failing for reasons I don't understand:
$ git branch
* my-branch
master
$ git push --force-with-lease origin my-branch -u
To gitlab.com:example/my-project.git
! [rejected] my-branch -> my-branch (stale info)
error: failed to push some refs to '[email protected]:example/my-project.git'
I tried a fetch to see if my local cache had somehow gotten out of sync:
$ git fetch
$ git push --force-with-lease origin my-branch -u
To gitlab.com:example/my-project.git
! [rejected] my-branch -> my-branch (stale info)
error: failed to push some refs to '[email protected]:example/my-project.git'
I tried simplifying the push command a bit:
$ git push --force-with-lease
To gitlab.com:example/my-project.git
! [rejected] my-branch -> my-branch (stale info)
error: failed to push some refs to '[email protected]:example/my-project.git'
I tried limiting the check to my branch:
$ git push --force-with-lease=my-branch:origin/my-branch
To gitlab.com:example/my-project.git
! [rejected] my-branch -> my-branch (stale info)
error: failed to push some refs to '[email protected]:example/my-project.git'
As you can see, it fails the same way every time.
Why is my push failing, and how do I fix it?
In this case it turned out that the problem was that the remote branch had been deleted, but there was still a copy of it in my local repo. Fetch doesn't delete local copies by default, which is why it had no effect.
Adding the --prune
option to my initial git pull
(before doing my rebase) corrects this problem.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments