-1

Problem: "Updates were rejected because the tip of your current branch is behind its remote counterpart" error while trying to push a (potentially long-running) bugfix/maintenance branch.

Setup: The development is done on the master branch. A commit, which is behind the master's HEAD by a number of commits, is tagged with dev-0.2 tag. I want to create a new (potentially long-running) branch (say, dev-0.2-bugfix) based on dev-0.2 tag and use the new dev-0.2-bugfix branch to track changes related to the dev-0.2 release.

What I did:

$ git checkout -b dev-0.2-bugfix dev-0.2
Switched to a new branch 'dev-0.2-bugfix

$ ..make changes to dev-0.2-bugfix files

$ ..commit changes to local dev-0.2-bugfix branch and now let's try to push it to remote

$ git push origin dev-0.2-bugfix
To file:////var/lib/git/Test.git
 ! [rejected]        dev-0.2-bugfix -> dev-0.2-bugfix (non-fast-forward)
error: failed to push some refs to 'file:////var/lib/git/Test.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.

$ git push origin dev-0.2-bugfix:dev-0.2-bugfix
To file:////var/lib/git/Test.git
 ! [rejected]        dev-0.2-bugfix -> dev-0.2-bugfix (non-fast-forward)
error: failed to push some refs to 'file:////var/lib/git/Test.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.

Any ideas how to resolve this? I want dev-0.2-bugfix to be created on the remote, currently dev-0.2-bugfix does not exits on the remote. I don't want to bring the latest changes from master as they were committed after the dev-0.2 tag had been created and are not a part of dev-0.2 release.

Thanks

Update: Tried forcing the push, it kind of worked (see below) but still did not create dev-0.2-bugfix on the remote:

$ git push -f origin dev-0.2-bugfix:dev-0.2-bugfix
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 2 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 419 bytes | 419.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0)
To file:////var/lib/git/Test.git
 + 337a471...0dd7573 dev-0.2-bugfix -> dev-0.2-bugfix (forced update)

 $ git branch -a
* dev-0.2-bugfix
  master
  remotes/origin/HEAD
  remotes/origin/master
Sdf
  • 79
  • 1
  • 6
  • Just like the hint says, you need to pull – DCTID Feb 17 '20 at 00:58
  • Does this answer your question? [git: "Updates were rejected because the tip of your current branch is behind.." but how to see differences?](https://stackoverflow.com/questions/45293263/git-updates-were-rejected-because-the-tip-of-your-current-branch-is-behind) – phd Feb 17 '20 at 11:39
  • https://stackoverflow.com/search?q=%5Bgit%5D+hint%3A+Updates+were+rejected+because+the+tip+of+your+current+branch+is+behind – phd Feb 17 '20 at 11:39
  • Dctid, Just like explained above, pulling the master branch would pull changes from the master that were committed after the dev-0.2 tag had been created. Those changes are not a part of dev-0.2 release and should not be in dev-0.2-bugfix branch. Or do you mean that I should pull the changes and then manually remove them again? Is there a better way that would allow to avoid this redundant work? Thanks – Sdf Feb 17 '20 at 12:46
  • 1
    Don't pull the `master` branch, pull the `dev-0.2-bugfix` branch. You say you created it but it appears that a branch with that name already exists on your remote. Either that or you've configured your local `dev-0.2-bugfix` to push to a remote branch of another name. – Calum Halpin Feb 17 '20 at 13:33
  • Calum, you are correct, `dev-0.2-bugfix` did exist on remote but did not show in `git branch -r` and that was causing the confusion. Thanks for your help. – Sdf Feb 17 '20 at 17:31

1 Answers1

0

The problem was that dev-0.2-bugfix branch was created on the remote but did not show in git branch -r or git branch -a and that was causing the confusion. See Remote branch is not showing up in "git branch -r" for more info. Thanks to everyone who responded.

Sdf
  • 79
  • 1
  • 6