*****git pull总结

简介: 当git clone之后,直接git pull它会自动匹配一个正确的remote url 是因为在config文件中配置了以下内容: 1 [branch "master"] 2 remote = origin 3 merge = refs/heads/master 表明: 1.git 处于master这个branch下时,默认的remote就是origin; 2.当在master这个brach下使用指定remote和merge的git pull时,使用默认的remote和merge。

当git clone之后,直接git pull它会自动匹配一个正确的remote url

是因为在config文件中配置了以下内容:

1 [branch "master"]
2     remote = origin
3     merge = refs/heads/master

表明:

1.git 处于master这个branch下时,默认的remote就是origin;

2.当在master这个brach下使用指定remote和merge的git pull时,使用默认的remote和merge。

 

但是对于自己建的项目,并用push到远程服务器上,并没有这块内容,需要自己配置

如果直接运行git pull,会得到如此结果:

 

复制代码
 1 $ git pull
 2 Password:
 3 You asked me to pull without telling me which branch you
 4 want to merge with, and 'branch.master.merge' in
 5 your configuration file does not tell me, either. Please
 6 specify which branch you want to use on the command line and
 7  try again (e.g. 'git pull <repository> <refspec>').
 8 See git-pull(1) for details.
 9 
10 If you often merge with the same branch, you may want to
11 use something like the following in your configuration file:
12 
13     [branch "master"]
14     remote = <nickname>
15     merge = <remote-ref>
16 
17     [remote "<nickname>"]
18     url = <url>
19     fetch = <refspec>
20 
21 See git-config(1) for details.
复制代码

在参考[2]中,有这样一段:

Note: at this point your repository is not setup to merge _from_ the remote branch when you type 'git pull'. You can either freshly 'clone' the repository (see "Developer checkout" below), or configure your current repository this way:

 

1 git remote add -f origin login@git.sv.gnu.org:/srv/git/project.git
2 git config branch.master.remote origin
3 git config branch.master.merge refs/heads/master   

 

因此通过git config进行如下配置:

1   $ git config branch.master.remote origin
2   $ git config branch.master.merge refs/heads/master

或者加上--global选项,对于全部项目都使用该配置。

 

执行完以上 命令,在config文件中配置了以下内容:

1 [branch "master"]
2     remote = origin
3     merge = refs/heads/master

 

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

假如 当前 仓库有 两个 分支,master 和 test1,当我们 执行了 以下 两条命令之后:

 

git config branch.test1.remote origin

git config branch.test1.merge refs/heads/test1

 

将在 在config文件中配置了以下内容:

1 [branch "test1"]
2     remote = origin
3     merge = refs/heads/test1

 GIT PULL命令详解

 

http://www.yiibai.com/git/git_pull.html

git pull命令的作用是,取回远程主机某个分支的更新,再与本地的指定分支合并。它的完整格式稍稍有点复杂。

$ git pull <远程主机名> <远程分支名>:<本地分支名>

比如,取回origin主机的next分支,与本地的master分支合并,需要写成下面这样。

$ git pull origin next:master

如果远程分支是与当前分支合并,则冒号后面的部分可以省略。

$ git pull origin next

上面命令表示,取回origin/next分支,再与当前分支合并。实质上,这等同于先做git fetch,再做git merge。

$ git fetch origin
$ git merge origin/next

在某些场合,Git会自动在本地分支与远程分支之间,建立一种追踪关系(tracking)。比如,在git clone的时候,所有本地分支默认与远程主机的同名分支,建立追踪关系,也就是说,本地的master分支自动”追踪”origin/master分支。

Git也允许手动建立追踪关系。

git branch --set-upstream master origin/next

上面命令指定master分支追踪origin/next分支。

如果当前分支与远程分支存在追踪关系,git pull就可以省略远程分支名。

$ git pull origin

上面命令表示,本地的当前分支自动与对应的origin主机”追踪分支”(remote-tracking branch)进行合并。

如果当前分支只有一个追踪分支,连远程主机名都可以省略。

 
$ git pull

上面命令表示,当前分支自动与唯一一个追踪分支进行合并。

如果合并需要采用rebase模式,可以使用–rebase选项。

$ git pull --rebase <远程主机名> <远程分支名>:<本地分支名>
如何联系我:【万里虎】www.bravetiger.cn 【QQ】3396726884 (咨询问题100元起,帮助解决问题500元起) 【博客】http://www.cnblogs.com/kenshinobiy/
目录
相关文章
|
1月前
|
开发工具 git 开发者
|
1月前
|
开发工具 git 开发者
Git Pull vs. Git Fetch:深度解析
【2月更文挑战第29天】
135 0
Git Pull vs. Git Fetch:深度解析
|
缓存 开发工具 git
【已解决】git pull 显示 Already up-to-date,但文件并没有更新
git pull 显示 Already up-to-date,但文件并没有更新
1257 0
|
3月前
|
存储 网络安全 数据处理
git远程操作,推送【push】,拉取【pull】,忽略特殊文件,配置别名,标签管理
git远程操作,推送【push】,拉取【pull】,忽略特殊文件,配置别名,标签管理
|
Linux 网络安全 开发工具
Linux 安装git,并且使用https方式 git pull 代码的免密操作
Linux 安装git,并且使用https方式 git pull 代码的免密操作
316 0
|
11月前
|
数据可视化 开发工具 Android开发
Android Git 拉取代码报错:error: cannot pull with rebase: Your index contains uncommitted changes.
造成原因:在使用Android Studio中Git的Commit Directory 将本地更改的代码保存到本地后,点击commit,发现提交不上去,发现本地有代码,这时候拉取代码,报错:cannot pull with rebase: Your index contains uncommitted changes.表示我的索引有未提交的改变
|
网络安全 开发工具 git
GIt远程仓库pull拉取代码
GIt远程仓库pull拉取代码
367 0
|
Shell 网络安全 开发工具
git使用问题总结
git使用问题总结
134 0
git使用问题总结
|
网络安全 开发工具 git
Git常用语法总结及分支冲突
Git常用语法总结及分支冲突
111 0
|
开发工具 git
Git Pull Failed 解决办法
Git Pull Failed 解决办法
Git Pull Failed 解决办法