How do I rename my Git 'master' branch to 'release'?

rename branch github
git rename
git rename remote
bitbucket rename branch
git rename master branch
github rename branch web
rename git branch locally
git rename branch to lowercase

We would like to enforce a new policy for our projects that the master branch now be called the release branch to ensure it is more clear as to how the branch should be used. Naturally, we will have develop and release candidate branches as well.

I understand I can rename the master branch locally by simply using the following:

git branch -m master release

However, that is only locally. Even if I push this up to the remote, the HEAD still points to the remote master branch. I want to get rid of the master branch completely and make the default local branch upon initial clone, be release.

How can I achieve this?

It seems that since the origin is on a Gitorious server, I get errors deleting the master branch. I'm trying to see now if it is possible to change this so that the default branch is 'release'.

git checkout -b release master    # Create and switch to the release branch
git push -u origin release        # Push the release branch to the remote and track it
git branch -d master              # Delete local master
git push --delete origin master   # Delete remote master
git remote prune origin           # Delete the remote tracking branch

Please note, if you are using GitHub you will need to first change your "default" branch on GitHub after step 3:

In your repository on github.com go SettingsBranchesDefault Branch. Change it to release and then do the rest of the steps.

How To Rename a Local and Remote Git Branch, How to Rename a Remote Git Branch? To start, you will need to rename a local branch by following the previous steps. Then delete the old branch and push the new one. You can do this easily with the following commands: git push origin --delete old-name git push origin :old-name new-name. Git Rename Files. Use git mv command to rename files and directories in current git repository. You can see that the same command is used to move files as well. The difference between both operations is that if you changed the filename only and destination is the same directory then it called rename. Syntax git mv [FILENAME] [NEW FILENAME] Example

Check out your master branch
git checkout master
Create your release branch and switch to it:
git branch release
git checkout release
Push that to the server
git push origin release
Delete the master branch reference on the server
git push origin :master
Delete the local master branch
git branch -d master

How to Rename a Local and Remote Git Branch – A Quick Guide, Git branches are an important part of the everyday workflow. Branches are a pointer to a snapshot of the changes you have made in Git. Branching helps cleaning� Let’s achieve the result with the steps described below: Renaming local branch to the new name To rename the local branch to the new name, use the git branchcommand followed by Pushing the new branch to remote Then you should push the new branch to remote: git push <remote><new_name> To reset

Note: This answer is intended for self-hosted Git servers where you have command line access.

Since trying to delete the remote master from a client indeed is not allowed and I do assume forbidding denyDeleteCurrent makes sense, I would not like to change that setting.

However, I found that the easiest way to rename your master iff you have command line access to the remote server is to run the rename command directly on remote.

This worked for me:

  1. Login via SSH to the remote git server
  2. Go to the xxx.git folder of your project
  3. run: git branch -m master release

Now the remote repository uses release as its default branch and any git clone on that repository from any client will check out the release branch by default.

It is very helpful also after setting up a bare repository to configure it to your needs.

How to Rename Git Local and Remote Branches, Rename your local branch. If you are on the branch you want to rename: 1. git branch -m new� git branch -a; How to Rename a Remote Git Branch? Although it isn’t possible to rename a remote branch directly, the process of renaming one involves these three easy steps: To start, you will need to rename a local branch by following the previous steps. Then delete the old branch and push the new one. You can do this easily with the

As previously stated by others, the issue here is Gitorious, which doesn't let you delete the HEAD branch per default. You have two options get around this problem. One is to log into the Gitorious server (with ssh), find the Git repository on the file server and add:

[receive]
        denyDeleteCurrent = warn

to the configuration.

An easier option is just to change the default branch. Go to you repository in the Gitorious web interface, press "Edit repository", and set "Head Change the symbolic ref the HEAD in the Git repository points to:". After you've done this you can delete the master branch.

Rename a local and remote branch in git – Multiple States , Rename a Local Branch � 1. Enter the name of the branch you want to change in your command line interface: git checkout old-branch You� For renaming files or folders use nothing but the git mv command. git mv takes at least two arguments, a source and a destination. If you want to move several files to a single path you may specify n sources but the last argument is the destination. Here’s what ‘git mv’ actually does:

If you run into this issue with GitHub, do the steps up until deleting the branch on remote. It will not let you do that. Then log into the Web interface and on the repository go SettingsBranchesDefault Branch. Change it to the new branch and do the rest of the steps.

How to Rename a Git Branch (Local and Remote), Renaming a repository � On GitHub, navigate to the main page of the repository. � Under your repository name, click Settings. Repository settings button � Under the � Renaming a local Git Branch is a matter of running a single command. However you can’t directly rename a remote branch, you need to push the renamed local branch and delete the branch with the old name. If you hit a problem or have feedback, leave a comment below. git.

Renaming a repository, The git remote rename command takes two arguments: An existing remote name, for example, origin; A new name for the remote, for example, destination� I can also update the tracking branch manually as seen here, but if you use git push -u origin main it'll do both. git branch -u origin/main main. The last thing to think about is if you have a CI/CD, GitHub Action, Azure DevOps pipeline or some other build system that pulls a specific branch. You'll just change that to main.

Renaming a remote, How to do I rename my repo � On GitHub, navigate to the main page of the repository. � Under your repository name, click Settings. � Under the� If you mean you want to rename the folder that contains the git repository, then just rename it. Git doesn’t care about the enclosing folder or directory. In more detail, if you mean: “How do I do ‘git clone’ a project, which creates a directory o

How to do I rename my repo? - How to use Git and GitHub, To change the name of an existing remote you'll need to use the git remote rename command. In order to change the name of your remote you� Under your repository name, click Settings. Under the Repository Name heading, type the new name of your repository. Click Rename.

Comments
  • Heh, fair enough. Long term worth is high enough to at least try.
  • Possible duplicate of How do I rename a local Git branch?
  • Some (remote) server refuse to delete the "default" branch (it's the case with Github). So you perhaps need to go on the server to choose another "default" branch for the time of the operations... On Github, this can be done in the "branch" view.
  • git branch now supports a --move flag git-scm.com/docs/git-branch#Documentation/git-branch.txt---move
  • When I attempt git push --delete, I get the following error: deletion of the current branch prohibited
  • You are using github or something similar, you need to make the default branch something else: matthew-brett.github.com/pydagogue/gh_delete_master.html or just leave master there and ignore it.
  • Yeah, we have a gitorious instance. Let me see if that is an option.
  • It looks like gitorious' commit hooks forbid the deletion of the master branch -- for no good reason that I can see :/
  • Same ! [remote rejected] branch (deletion of the current branch prohibited) will happen with Bitbucket. Switch the "Main Repository' in the settings screen (under the gear icon).
  • I can tell by these steps I will run into the same error as I mentioned above.
  • @KyleHayes That's a configuration issue of the server. Though it is this way by default, the process to alter that should either be apparent to the user or easily discoverable on Stackoverflow
  • You have to switch to another branch before you can delete a branch.
  • I got the same error as the one I posted in @Adam's comment when I got to the git push origin :master command.