在项目开发和维护中,经常需要从一个已有的分支拉取出一个新的分支,每次都记不住,所以现在将其记录下来,方便以后查看:
1:需要切换到被拉取的分支,并且拉取项目,命令如下:
$git checkout master $git pull
2:接着创建一个新分支,并且切换到新的分支:
$git checkout -b newbranch
Switched to a new branch 'dev'
上述命令是一步完成创建和切换,也可以先创建,在切换:
$git branch newbranch $git checkout newbranch
3:把本地分支push到远端:
$git push origin newbranch
4:拉取远端分支
$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> newbranch
5:这说明,当前分支还没有和本地分支进行关联,下面进行关联
git branch --set-upstream-to=origin/<branch> newbranch
6:再次拉取,完成任务。
$git pull