Apparently, it is not possible to rename a remote branch directly. You need to rename the local branch push it to a new remote branch and delete the remote branch then:
#bash
# If you are not on the branch to rename, do
git branch -m <old_name> <new_name>
# or check it out
git checkout <old_name>
git branch -m <new_name>
# Push it to the remote repo and make it track at the same time
git push origin -u <new_name>
# Delete the old branch in the remote repo
git push origin --delete <old_name>
You might run into problems, e.g. when you already created the new remote branch, maybe using the branch functionality in JIRA to have a link between branch and issue. The symptom is when running the push to the new remote:
#bash
To ssh://git@stash-prod.pnet.ch/adw/adw1.git
! [rejected] bugfix/kellnerth/SGA-1872-abhangigkeiten-in-arbitrary--monthly--outbound -> bugfix/kellnerth/SGA-1872-abhangigkeiten-in-arbitrary--monthly--outbound (non-fast-forward)
error: failed to push some refs to 'ssh://git@stash-prod.pnet.ch/adw/adw1.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
This behaviour is independent of pulling from the repository. You can push the new branch to remote by forcing it, e.g.#bash
git push -f origin <new_name>
Apparently it is not a good solution. I ended up with two local branches apart from the "prefix" origin/ identically named. The local "origin" branch was not tracking any
No comments:
Post a Comment