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

大兔子大兔子 提交于 2019-11-28 15:09:47
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
Jeff Ferland

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.

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 it's default branch and any git clone on that repository from any client will check out the release branch by default.

Very helpful also after setting up a bare repository to configure it to your needs.

Ideally, you want to setup tracking, so do this:

git push origin HEAD:release
git checkout --track origin/release

Now, you want to delete the others?

git branch -d master
git push origin :master

Simple!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!