您的位置:首页 > 其它

Git分支管理

2017-10-14 10:16 162 查看

Git分支管理

获取远程目录

git clone ssh://UserName@RemoteIp/ProjectPath # 克隆远程git目录

获取远程仓库分支

git clone https://github.com/openstack/taskflow.git -b branch # 获取远程对应分支
git checkout branch # 切换到对应分支

$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/stable/kilo
remotes/origin/stable/liberty
remotes/origin/stable/mitaka

$ git checkout stable/kilo
Branch stable/kilo set up to track remote branch stable/kilo from origin.
Switched to a new branch 'stable/kilo'

$ git branch
master
* stable/kilo
$

更新分支代码

git pull # 获取远程仓库对应分支的更新并合入本地分支
git fetch remote remote_branch:local_branch # 获取远程仓库remote的remote_branch分支代码到本地的local_branch分支上,一般当出现git pull失败的时候,使用此种方式将远程对应分支缓存到本地,然后使用git merge local_branch的方式来更新本地分支

$ git pull
Already up-to-date.

$ git fetch origin stable/kilo:tmp
From https://github.com/openstack/taskflow
* [new branch]      stable/kilo -> tmp

同步代码到远程仓库

git push # 同步当前分支到远程仓库对应分支
git push remote local_branch:remote_branch # 同步本地local_branch分支的代码到remote仓库的remote_branch分支

合并分支代码

git merge branch # 合并branch分支的代码到当前分支
git cherry-pick id # 合并其他分支的某次提交到当前分支,如果遇到冲突,需要手动修复冲突,然后使用git add添加冲突文件,然后执行git cherry-pick --continue

批量更新分支到远程仓库

git show-ref # git的ref相当于代码中指针的概念,每一次提交或者分支其实都是一个引用,git clone创建的副本都保存了完整的引用列表,通过

git push origin "refs/remote/*:refs/heads/*"
可以将本地的其他分支指针同步到服务端(服务端恢复),其中
tags
是唯一的,所以可以使用
git push origin "refs/tags/*:refs/tags/*"
恢复

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: