Rename remote branch

I have created a local branch X that at some point I pushed to remote server (origin)

git push origin X

I realized it's a bad idea to have branch named X and want it to be called Y The problem is that I've already pushed the branch to the repository.

Is it safe to delete it from the server and push it under a new name like this ?

push origin :X

// 'clone ' the branch under a new name locally ( X-> Y)

push origin Y

What will happen to the people that already fetched from the server. Say that they already made a branch locally based on the old X name BUT they did not make any changes locally or pushed them to the server for the old X branch.


other people will keep a pointer to branch X (as origin/X ) in their repository until they run git remote prune origin . it's left as a stale branch

when fetching/pulling they will get a second point to (newly created) branch Y (as origin/Y )

branching and merging is not affected by this.

so, as long as all commits are still reachable from your branch, renaming is fine.


If others have pulled the branch to their local repositories it is not safe to delete it. One route to consider is deleting all the files from the old branch. Leave a README pointing to the new branch.

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

上一篇: svn主分支返回主干

下一篇: 重命名远程分支