Branch Renaming in GitLab
2 min readJan 17, 2025
Unlike GitHub, GitLab doesn't allow renaming the origin branch from the remote is a known fact. (Process of renaming the branches in Github/Remote as below)
As GitLab doesn't allow the renaming of the branches in origin / remote; the following alternative can be considered to rename the remote branch/branches.
Steps for Branch Renaming
If <old-branch-name> is poc-branch
And <new-branch-name> is poc-amended
- Rename the Local Branch
git branch -m poc-branch poc-amended
- Push the Renamed Branch to Remote
git push origin poc-amended
- Update the Remote Tracking Branch
git psuh --set-upstream origin poc-amended
- Delete the Old Branch from the Remote
(using CLI as below or from WebUI)git push origin --delete poc-branch
- [Optional] Update Default Branch in GitLab — Refer below
- [Optional] Inform Team Members — Refer below
In the above approach, the code commit history for the branch will be preserved.
Update Default Branch in GitLab
- Log in to GitLab: Navigate to your project in GitLab.
- Go to Repository Settings:
Select Settings → Repository. - Change the Default Branch:
Under the Default Branch section, select the new branch name from the dropdown. - Protect the New Branch (Optional):
If the branch is protected, update its protection settings under
Settings → Repository → Protected Branches.
Let your team know about the branch name change so they can update their local repositories:
- Run the following to sync with the updated remote branch names
git fetch --prune
- Check out the new branch locally
git checkout poc-amended