讲解的命令:
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/*