
So first check out to your new named branch.

If you delete the old branch without pulling you may loose newly changes done by any developers. Or make sure that you are in sync with the remote branch for that you need to pull the changes.
Git rename a branch code#
push your newly renamed branch and track that new branch with localīefore deleting your old branch in remote make sure that you have the latest version of the code in local from the remote.with these three steps you can rename git remote branch. So now we have to change this name in the remote.įor that, you need to follow three steps. Using the above commands, we have changed the branch name in local. This command will change the branch name in locally not in remote. If you are in one branch and if you want to change another branch you can use above command. git branch –m new_branch_name If It Is Another Branch: git branch -m old_branch_name new_branch_name This command will rename your current local branch but not remote branch. If you want to change the current branch which you are in right now you, can use below command. Once this is complete, you can attempt to delete the "master" branch in U-M GitLab again.Git Rename Local Branchs If It Is A Current Branch: Verify on page refresh that the default repository branch is "main" by expanding the "Default Branch" section again.In the same repository settings page as above, in the 'Default Branch" section, switch the dropdown menu from "master" to "main", then click the green "Save Changes" button.Verify on page refresh that your "main" branch is listed properly as "protected".In the same repository settings page as above, in the "Protected Branches" section, fill out the form to protect your new "main" branch, and click the green "Protect" button.Expand the "Protected Branches" section, and select "Unprotect" on the 'master' branch.In the left-side navigation, under "Settings", select "Repository".What is forking a branch Forking is a way to clone a repository at a specific point and modify it from there. old is the name of the branch you want to rename and new is the new name for the branch.
To rename a branch, run git branch -mGit rename a branch update#
the simple answer to your question is yes, rename it but update your development team that renamed the branch if any of then already pulled it out from your main server. You'll need to resolve this before you can go on. You right, there is no need to understand what is going on beyond the scenes unless you are interested in knowing how git does the magic. Additionally, your old "master" might be set as "protected". ! master (refusing to delete the current branch: refs/heads/master)Įrror: failed to push some refs to GitLab, like other code-hosting platforms, automatically defines a "default" branch, and deleting this branch is not allowed. In many cases, however, you will see an error message like the following one: To Let's go on and remove the old "master" branch on the remote: $ git push origin -delete masterĭepending on your exact setup, this might have worked and the renaming is successful. We now have a new branch on the remote named "main". Make sure your current local HEAD branch is still "main" when executing the following command: $ git push -u origin main Instead, we'll have to create a new "main" branch and then delete the old "master" branch. In this second step, we'll have to create a new branch on the remote named "main" - because Git does not allow one to simply "rename" a remote branch. Renaming the Remote "master" Branch in U-M GitLab The local branch has been renamed - but we now need to make some changes in the remote repository in U-M GitLab as well. Your branch is up to date with 'origin/master'. Then, check to see if the rename has worked as expected: $ git status The first step is to rename the "master" branch in your local Git repository: $ git branch -m master main

How do I rename the "master" Branch in a Git Repository? Resolution Renaming the Local "master" Branch
