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

  1. Rename the Local Branch
    git branch -m poc-branch poc-amended
  2. Push the Renamed Branch to Remote
    git push origin poc-amended
  3. Update the Remote Tracking Branch
    git psuh --set-upstream origin poc-amended
  4. Delete the Old Branch from the Remote
    (using CLI as below or from WebUI)
    git push origin --delete poc-branch
  5. [Optional] Update Default Branch in GitLab — Refer below
  6. [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

  1. Log in to GitLab: Navigate to your project in GitLab.
  2. Go to Repository Settings:
    Select SettingsRepository.
  3. Change the Default Branch:
    Under the Default Branch section, select the new branch name from the dropdown.
  4. Protect the New Branch (Optional):
    If the branch is protected, update its protection settings under
    SettingsRepositoryProtected Branches.

Let your team know about the branch name change so they can update their local repositories:

  1. Run the following to sync with the updated remote branch names
    git fetch --prune
  2. Check out the new branch locally
    git checkout poc-amended

--

--

Hirosh Tharaka
Hirosh Tharaka

Written by Hirosh Tharaka

BSc(Hons), CSM®, ISTQB® (CTFL, CTAL-TTA, CTAL-TM) | Technical Writer | Technical Tester (QA Lead)

No responses yet