今天记录一下使用git命令新建远程分支的操作,因为公司的代码管理仓库界面没找到新建分支的操作界面,无奈只能通过git命令来新建分支。
1、新建本地分支
首先,你的至少应该已经有了一个master分支,然后你再master分支下面执行下面命令创建分支:
#git checkout -b feature
PS C:\Users\jelly\Desktop\Gopath\src> git checkout -b feature
Switched to a new branch 'feature'
PS C:\Users\jelly\Desktop\Gopath\src>
PS C:\Users\jelly\Desktop\Gopath\src>
PS C:\Users\jelly\Desktop\Gopath\src> git branch
dev
* feature
master
PS C:\Users\jelly\Desktop\Gopath\src> git branch -a
dev
* feature
master
remotes/origin/dev
remotes/origin/master
从上面我们可以看到我远程分支上面目前只有两个分支:
remotes/origin/dev
remotes/origin/master
通过上面的命令git checkout -b feature我创建了一个本地分支feature,我当时执行这个命令的时候是处于master分支的,所以创建出来的分支是基于master创建的feature,此时远程分支上面还没有。
2、推送到远程分支
执行下面的命令将刚新建的本地分支推送到远程仓库:
#git push -u origin feature
PS C:\Users\jelly\Desktop\Gopath\src> git push -u origin feature
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: Create a new pull request for 'feature':
remote: https://code.com/CBC_XXAQ_CodeAudit/CodeAudit_manage/compare/master...feature
remote:
remote: . Processing 1 references
remote: Processed 1 references in total
To https://code.com/CBC_XXAQ_CodeAudit/CodeAudit_manage.git
* [new branch] feature -> feature
Branch 'feature' set up to track remote branch 'feature' from 'origin'.
PS C:\Users\jelly\Desktop\Gopath\src>
PS C:\Users\jelly\Desktop\Gopath\src>
PS C:\Users\jelly\Desktop\Gopath\src>
PS C:\Users\jelly\Desktop\Gopath\src>
PS C:\Users\jelly\Desktop\Gopath\src>
PS C:\Users\jelly\Desktop\Gopath\src> git branch -a
dev
* feature
master
remotes/origin/dev
remotes/origin/feature
remotes/origin/master
从上面的代码可以看出,当执行这个推送命令之后,再次查询远程分支,远程分支已经有数据了,至此git命令行创建远程分支已经完成了,你可以在远程额操作界面看到新建的分支了。