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