Git命令可以很方便地重命名本地分支:
- git branch -m <old_branch_name> <new_branch_name>
如果想在远程重命一个分支名,则须使用以下思路:
- 在本地的clone版本中重命名分支
- 删除远程待修改的分支名
- 则本地的新分支名push到远程
以下是例子,首先是本地重命名:
- weli@power:~/projs/resteasy/forked$ git branch -m RESTEASY_JAXRS_1_2_1_GA_02_patch01 RESTEASY_JAXRS_1_2_1_GA_CP02_patch01
接下来删除远程待修改的分支名:
- weli@power:~/projs/resteasy/forked$ git push origin :RESTEASY_JAXRS_1_2_1_GA_02_patch01
- To git@github.com:liweinan/Resteasy.git
- - [deleted] RESTEASY_JAXRS_1_2_1_GA_02_patch01
最后将本地的新分支名push到远程:
- weli@power:~/projs/resteasy/forked$ git push origin RESTEASY_JAXRS_1_2_1_GA_CP02_patch01
- Counting objects: 274, done.
- Delta compression using up to 8 threads.
- Compressing objects: 100% (140/140), done.
- Writing objects: 100% (144/144), 12.50 KiB, done.
- Total 144 (delta 69), reused 30 (delta 0)
- To git@github.com:liweinan/Resteasy.git
- * [new branch] RESTEASY_JAXRS_1_2_1_GA_CP02_patch01 -> RESTEASY_JAXRS_1_2_1_GA_CP02_patch01
补充:
本地git 操作
git branch <new_branch_name> 建立本地 local branch
git branch -m <old_name> <new_name> 改名字 (如果有同名會失敗,改用 -M 可以強制覆蓋)
git branch 列出目前有那些 branch 以及目前在那個 branch
git checkout <branch_name> 切換 branch (注意到如果你有檔案修改了卻還沒 commit,會不能切換 branch,解法稍後會談)
git checkout -b <new_branch_name> (<from_branch_name>) 本地建立 branch 並立即 checkout 切換過去
git branch -d <branch_name> 刪除 local branch
源自:http://ihower.tw/blog/archives/2620
参考资料:
[1] http://stackoverflow.com/questions/1526794/git-rename-remote-branch