Default behaviour of 'git pull'

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.


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.


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.

Tags:

Git

Git Pull