当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 <远程主机名> <远程分支名>:<本地分支名>

*****git pull总结的更多相关文章

  1. git pull和git fetch的区别

    Git中从远程的分支获取最新的版本到本地有这样2个命令:1. git fetch:相当于是从远程获取最新版本到本地,不会自动merge Git fetch origin master git log ...

  2. 聊下git pull --rebase

    有一种场景是经常发生的. 大家都基于develop拉出分支进行并行开发,这里的分支可能是多到数十个.然后彼此在进行自己的逻辑编写,时间可能需要几天或者几周.在这期间你可能需要时不时的需要pull下远程 ...

  3. Git fetch和git pull的区别

    Git中从远程的分支获取最新的版本到本地有这样2个命令:1. git fetch:相当于是从远程获取最新版本到本地,不会自动merge git fetch origin mastergit log - ...

  4. git pull 冲突解决

    这个意思是说更新下来的内容和本地修改的内容有冲突,先提交你的改变或者先将本地修改暂时存储起来. 处理的方式非常简单,主要是使用git stash命令进行处理,分成以下几个步骤进行处理. 1.先将本地修 ...

  5. git pull 然后 ahead of origin/master * commit 消失

    本来显示 your branch is ahead origin/master * commit后来也许在master merge 这个分支后, 然后git pull, 就显示Your branch ...

  6. git pull提示当前不在某个分支上

    $ git pull You are not currently on a branch, so I cannot use any 'branch.<branchname>.merge' ...

  7. git pull 和本地文件冲突问题解决

    具体方法如下 git pull origin 分支 //出现错误 git stash  缓存起来 git pull origin 分支 git stash pop //还原 git stash cle ...

  8. git pull错误

    1. Pull is not possible because you have unmerged files. 症状:pull的时候 $ git pull Pull is not possible ...

  9. 关于git中git pull --rebase中的一些坑

    在公司里面,每次我更改完代码,准备pull最新代码时,总是会遇到各种各样的问题.,因为对应的问题不同,解决方法很多.但是比较通用的办法还是有的: git pull --rebase   //报错时 g ...

  10. git merge git pull时候遇到冲突解决办法git stash

    在使用git pull代码时,经常会碰到有冲突的情况,提示如下信息: error: Your local changes to 'c/environ.c' would be overwritten b ...

随机推荐

  1. capacilitys 持续集成

    目前看好像是说以docker为例来看看这个权限到底是怎么来的? 可以通过在二进制上setcap得到,也可以通过函数自己用setcap得到,两种方法,docker肯定是第二种方法啊,docker中间肯定 ...

  2. java enum naming rules & Pascal case, Camel case, Uppercase

    java enum naming rules Constant & all Capital Case https://stackoverflow.com/questions/3069743/c ...

  3. Codeforces Round #401 (Div. 1) C(set+树状数组)

    题意: 给出一个序列,给出一个k,要求给出一个划分方案,使得连续区间内不同的数不超过k个,问划分的最少区间个数,输出时将k=1~n的答案都输出 比赛的时候想的有点偏,然后写了个nlog^2n的做法,T ...

  4. BZOJ_day9

    哇,一道巨大的水题害得我wa了无数次... 总结一下教训 大家一定记住(给我自己看的)  位运算 一定要加()!!! 重要的事情说三遍  位运算 一定要加()!!! 位运算 一定要加()!!! 位运算 ...

  5. MySQL使用笔记(二)数据库基本操作

    By francis_hao    Dec 11,2016 数据库是什么 数据库是什么呢?对于MySQL来说,数据库是存储数据库对象的容器,参考[1]中的简单解释是:数据库是一个拥有特定排放顺序的文件 ...

  6. shell脚本应用

    解析乱的日志文件到临时文件中,然后用awk  1004  cd /usr/local  1005  ll  1006  cd pttmsg/  1007  ll  1008  cd msgbin-2/ ...

  7. POJ2240:Arbitrage(最长路+正环)

    Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29374   Accepted: 12279 题目链接: ...

  8. PHP 抽象类,接口,抽象方法,静态方法

    1.Abstract class(抽象类) 抽象类是指在 class 前加了 abstract 关键字且存在抽象方法(在类方法 function 关键字前加了 abstract 关键字)的类. 抽象类 ...

  9. React 开发常见报错解决方法

    1. 使用 redux 的异步 action 时浏览器报错: Error: Actions must be plain objects. Use custom middleware for async ...

  10. Java并发(5)- ReentrantLock与AQS

    引言 在synchronized未优化之前,我们在编码中使用最多的同步工具类应该是ReentrantLock类,ReentrantLock拥有优化后synchronized关键字的性能,又提供了更多的 ...