git建立新分支並push到遠端伺服器
1. 切換到被copy的分支(master),並且從遠端拉取最新版本
$git checkout master
$git pull
2. 從當前分支拉copy開發分支,例如我要建立新分支v2為例
$git checkout -b v2
Switched to a new branch 'v2'
3. 把新建的分支push到遠端
$git push origin v2
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> v2
經過驗證,當前的分支並沒有和本地分支關聯,根據提示進行下一步:
5. 關聯
$git branch --set-upstream-to=origin/v2
注意:這裡branch之後都是沒有空格的,如果有空格則是錯誤命令
6. 再次拉取 驗證
$git pull
使用Git下載指定分支命令為:git clone -b 分支名倉庫地址
使用Git下載v2分支程式碼,使用命令:git clone -b v2 http://192.168.16.16:3000/codeAdmin/kg_web_api.git 如下圖所示: