Git_Git远程操作_第2课_Git远程协作的主要命令

讲解的命令:

git remote

git clone

git fetch

git pull

git push


================================

命令:git remote


#增加远程仓库

git remote add origin git@github.com:michaelliao/learngit.git




================================================


命令: git clone 

git clone 支持协议有 ssh, http , git ... 




========================



命令: git fetch


#获取远程的所有分支和数据

git fetch 



示例:

git fetch 

 #用远程跟踪分支合并本地当前分支

git merge origin/master 


 #只更新指定分支的信息

git fetch origin branchName



#用/origin/master 更新 本地 master 信息,需要merge
git fetch origin master:remotes/origin/master


tips:

git无法pull仓库refusing to merge unrelated histories 解决方案


因为他们是两个不同的项目,要把两个不同的项目合并,git需要添加一句代码,在git pull,这句代码是在git 2.9.2版本发生的,最新的版本需要添加--allow-unrelated-histories

假如我们的源是origin,分支是master,那么我们 需要这样写git pull origin master --allow-unrelated-histories需要知道,我们的源可以是本地的路径







=====================

命令: git pull



#git pull 相当于 git fetch 与 git merge 的混合体 

git pull



#只更新单独的一个分支

git pull origin branchName 



#将远程的branch与 本地的localBranchName进行绑定

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> localBranchName








=========================


命令: git push




#推送本地的tag到远程仓库中

git push --tags 



#仅推送本地master分支的内容

git push origin master 




#删除远程分支 && 并删除本地该分支
方法一
git branch -d branchName #先删除本地分支
git push --delete origin branchName #再推送删除远程分支


方法二
git branch -d branchName #先删除本地分支

git push origin :branchName(remote) #以空分支替代远程的分支




=====配置本地库与远程库的对应关系===

#较为复杂的一种配置
git push origin master:qa/master 将本地的master分支 推送到 远程的qa/master上


#或者直接修改配置local的配置文件
#在 origin 等加上一条配置
push = refs/heads/*:refs/qa/* 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值