项目中遇到项目修改git分支的需求,闲来无事,愿将毕生所学传授大家,不求感恩图报,只求大家关注!
假设分支名称为old_Name,想要修改为 new_Name
1. 本地分支重命名(还没有推送到远程)
$ git branch -m old_Name new_Name
2. 远程分支重命名
(已经推送远程-假设本地分支和远程对应分支名称相同)
a. 重命名远程分支对应的本地分支
$ git branch -m old_Name new_Name
b. 删除远程分支
$ git push --delete origin old_Name
c. 上传新命名的本地分支
$ git push origin new_Name
d.把修改后的本地分支与远程分支关联
$ git branch --set-upstream-to origin/new_Name
关联目的是,如果在本地分支下进行pull 和push操作时 ,便不需要指定远程的分支。
如果在没有关联且没有指定分支的情况下,直接使用 git pull 命令,会提示你如下信息:
Window:projects user$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> pj-risk
解决办法:
例如,使用命令git branch --set-upstream(test为创建的分支)
$ git branch --set-upstream debug origin/new_Name
小程序/微信商城/建站业务,望大家支持一下!