I need to rename branch “branch” to “branch_old” in gitlab,
I searched for it and found that I need to do the following
Checkout the branch locally.
Rename it locally
delete remote branch
push the locally renamed branch to remote.
When I do this I get errors of pre-recive hooks rejecting the deletion of protected branches.
Then I go to gitlab and delete the protected branch via GUI and when I try to push the new branch, I get the following
$ git push --set-upstream origin branch_old
Counting objects: 8450, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4249/4249), done.
Writing objects: 100% (8450/8450), 5.03 MiB | 3.19 MiB/s, done.
Total 8450 (delta 6592), reused 5965 (delta 4199)
remote: Resolving deltas: 100% (6592/6592), completed with 695 local objects.
remote: fatal: bad object 0000000000000000000000000000000000000000
To :testlab/.git
[new branch] branch_old -> branch
Branch ‘branch_old’ set up to track remote branch ‘branch’ from ‘origin’.
In gitlab gui, I see the “branch” being restored.
What am I doing wrong? what is the correct way to rename a branch in Gitlab.?
Try to disable the branch protection in the settings/repository page. Check the sections
Default Branch
and
Protected Branches
After that:
Checkout the branch locally.
$ git checkout branch
Rename it locally
$ git checkout -b branch_old
delete remote branch
$ git push --delete origin branch
push the locally renamed branch to remote.
git push --set-upstream origin branch_old
Hello all,
Thanks a lot for your help. I was deleting the remote branch in Gitlab via GUI and that was not helping.
I tried deleting the remote branch by git on command line and it worked.
Regards
netkey:
You can create a branch named “branch_old” from “branch”, and then delete the branch named “branch”
That’s what I did in the same situation.
Easy going, worked like a charm.
(My branch to rename was not protected, so I did not have to unprotect it before deleting.)
“git branch -m oldbranchname newbranchname” only changes your local repo.
You need to push:
git push origin HEAD:newbranchname
Then you need to delete the old remote branch:
git push origin --delete oldbranchname
bhadram222:
I had to Used this command
git branch -m old branch name new branch name
. In terminal its showing correct but its not updated in browser. Please let me know any having knowledge about this and why
dachshunds are considered worst
breed?
It can be done by
rename the branch locally:
git branch -m old-branch-name new-branch-name
then, delete the old branch from the remote:
git push origin --delete old-branch-name
Finally, push the new branch to the remote and set the upstream:
git push origin new-branch-name
git push --set-upstream origin new-branch-name
Inform your team members about the branch name change, so everyone is aware and can update their local repositories accordingly.