Default behaviour of 'git pull'

醉酒当歌 提交于 2020-04-12 21:24:11

问题


Why is that git pull pulls everything including newly created remote branches but git pull origin master does not?

I'm using git version 2.9.3.windows.2.


回答1:


When you specify no branches, the default settings are used. The default means to fetch and update all branches existing in the remote repository.

See documentation for details:

git pull [options] [<repository> [<refspec>…​]]

<refspec> specifies which refs to fetch and which local refs to update. When no <refspec>s appear on the command line, the refs to fetch are read from remote.<repository>.fetch variables instead (see git-fetch[1]).

Source: https://git-scm.com/docs/git-pull

The referenced documentation explains:

You often interact with the same remote repository by regularly and repeatedly fetching from it. In order to keep track of the progress of such a remote repository, git fetch allows you to configure remote.<repository>.fetch configuration variables.

Typically such a variable may look like this:

[remote "origin"]
  fetch = +refs/heads/*:refs/remotes/origin/*

The example above will fetch all branches that exist in the origin (i.e. any ref that matches the left-hand side of the value, refs/heads/*) and update the corresponding remote-tracking branches in the refs/remotes/origin/* hierarchy.

Source: https://git-scm.com/docs/git-fetch#CRTB

The behavior is default because it allows you to synchronize the whole repositories at once. If you don’t want to update all local branches at once, use git fetch to synchronize the repositories and git merge origin/<branch> to update each single local branch.




回答2:


In Layman Language, git pull fetches everything from your remote (all new branches and updates old branches) and by default, it will do so for origin. If you have any other remote like upstream you have to specify that like git pull upstream and it will update everything from upstream.




回答3:


Its is really simple

When you say git pull everything irrespective of any hooks and filter gets added to your local. In short you get everything from your remote and update the .git folder. You can go to folder .git/logs/refs/remotes/origin/ you will see the branches all that you have on your local.

So, Now I typed git pull from my cmd.

What happen behind the curtain is irrespective of the local branches you have. It hooks up the origin and get every from there to your local.

But, when I type git pull origin master. In this you give a path specification from origin you need a latest head of master branch. Then only master brach gets pulled and refreshed as it is on remote

So, origin master is a path spec they called in git language for path.



来源:https://stackoverflow.com/questions/40739305/default-behaviour-of-git-pull

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!