开发者

Renaming remote git branch

开发者 https://www.devze.com 2023-03-28 07:46 出处:网络
I have 2 git branches: master and experimental. 开发者_如何学运维Experimental became good, I want to make it the master. I figured I would rename to shuffle things around, but here is what I got:

I have 2 git branches: master and experimental.

开发者_如何学运维

Experimental became good, I want to make it the master. I figured I would rename to shuffle things around, but here is what I got:

nutebook:Stuff nathan$ git remote rename master old
error: Could not rename config section 'remote.master' to 'remote.old'

I use GitHub and Git-Tower.


The following is a guide to rename your master branch. It will work just as easily to rename your experimental branch.

Here's how I did the renaming.

First, in your working tree, locally rename master to something else.

git branch -m master old-dev

Renaming a branch does work while you are on the branch, so there's no need to checkout something else.

Then, locally rename the maintenance branch (2.63-branch) to master:

git branch -m 2.63-branch master

Now, time to mess with the remote. Just in case you screw up, you might want to make sure you have a current backup. First, delete the remote's master:

git push origin :master

And now, give the remote your new master:

git push origin master:refs/heads/master

Update: When creating a new branch, the refs/heads/ prefix is needed on the remote side. If the branch already exists (as master did above) only the branch name is required on the remote side.

... and your now-renamed old master:

git push origin old-dev:refs/heads/old-dev

Finally, delete the old name of your maintenance branch to prevent confusion:

git push origin :2.63-branch

Clients will now get the 'new' master branch when they pull.

see this site.


I think the easiest way is to checkout the experimental branch, delete the remote master branch, then push the local experimental one as the new remote master one.

// delete the remote master branch by pushing null
// (the space in front of the semicolon) in this branch
git push origin :master
// push local experimental to remote master
git push origin experimental:master


master is a branch, not a remote like origin is. if you want to have your experimental work to your master branch, simply merge it in:

git checkout master
git merge experimental


If you're a Mac user, you can use the GitHub Mac App (https://mac.github.com/) to rename branches.


What you tried to do was rename a remote repo from "master" to "old". To rename a branch on another repo, just delete it with

git push <remote> :<branch name>

then push it as something else.

0

精彩评论

暂无评论...
验证码 换一张
取 消