Why is `git push --force-with-lease` failing with "rejected ... stale info" even when my local repo is up to date with remote?

Laurence Gonsalves

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?

Laurence Gonsalves

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why does Git show my local "pull from remote" when I push my commit to the remote repo?

From Dev

unable to push my local git repo to the remote repo

From Dev

Can I add a file to my local Git repo but not push it to remote

From Dev

git push failing on a local gitlab repo

From Dev

Force a certain version of git on push to remote repo

From Dev

Force git to update my local repo when pulling

From Dev

fatal: Could not read from remote repository. When I push my local repo to remote server

From Dev

Push local new Git repo to existing remote repo as branch?

From Dev

Git push force issue - Unable to force local changes on top of remote

From Java

Push local Git repo to new remote including all branches and tags

From Dev

Git pull failing due to "local changes" even when there are none?

From Dev

Push git alias to remote repo

From Dev

Failure to push to remote repo in Git

From Dev

Why git push --force transfer blobs already included in remote

From Dev

Cannot push to heroku after adding a remote heroku repo to my existing local repo

From Dev

Netbeans showing no local branches when trying to push to git repo

From Dev

Git status says up-to-date with remote even though it's not

From Dev

reassign an existing remote repo to my local repo

From Java

push --force-with-lease by default

From Dev

Why doesn't my Git status show me whether I'm up-to-date with my remote counterpart?

From Dev

Push local git to new remote

From Dev

push new git branch to remote repo on eclipse

From Dev

How do I tell git to ignore my local changes, but leave the file in my remote repo?

From Dev

Push local repo to new sub-directory of remote repo

From Dev

Setting up remote git repo that is on an encrypted drive?

From Dev

How to compare local with remote git repo in PhpStorm?

From Dev

Check if local git repo is ahead/behind remote

From Dev

Merge local git repo with remote one

From Dev

How to compare GIT Remote Repo and local in Netbeans

Related Related

  1. 1

    Why does Git show my local "pull from remote" when I push my commit to the remote repo?

  2. 2

    unable to push my local git repo to the remote repo

  3. 3

    Can I add a file to my local Git repo but not push it to remote

  4. 4

    git push failing on a local gitlab repo

  5. 5

    Force a certain version of git on push to remote repo

  6. 6

    Force git to update my local repo when pulling

  7. 7

    fatal: Could not read from remote repository. When I push my local repo to remote server

  8. 8

    Push local new Git repo to existing remote repo as branch?

  9. 9

    Git push force issue - Unable to force local changes on top of remote

  10. 10

    Push local Git repo to new remote including all branches and tags

  11. 11

    Git pull failing due to "local changes" even when there are none?

  12. 12

    Push git alias to remote repo

  13. 13

    Failure to push to remote repo in Git

  14. 14

    Why git push --force transfer blobs already included in remote

  15. 15

    Cannot push to heroku after adding a remote heroku repo to my existing local repo

  16. 16

    Netbeans showing no local branches when trying to push to git repo

  17. 17

    Git status says up-to-date with remote even though it's not

  18. 18

    reassign an existing remote repo to my local repo

  19. 19

    push --force-with-lease by default

  20. 20

    Why doesn't my Git status show me whether I'm up-to-date with my remote counterpart?

  21. 21

    Push local git to new remote

  22. 22

    push new git branch to remote repo on eclipse

  23. 23

    How do I tell git to ignore my local changes, but leave the file in my remote repo?

  24. 24

    Push local repo to new sub-directory of remote repo

  25. 25

    Setting up remote git repo that is on an encrypted drive?

  26. 26

    How to compare local with remote git repo in PhpStorm?

  27. 27

    Check if local git repo is ahead/behind remote

  28. 28

    Merge local git repo with remote one

  29. 29

    How to compare GIT Remote Repo and local in Netbeans

HotTag

Archive