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

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?

EDIT: 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

Checkout 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

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 config.

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.

链接地址: http://www.djcxy.com/p/2612.html

上一篇: 使用git push的Git问题

下一篇: 如何将我的git'master'分支重命名为'release'?