Search code examples
gitgit-pull

What's the difference between putting Origin and not putting in using Git?


hope you're doing well!

Actually, I want to know the difference between putting Origin using Git in a command and not putting it.

for instance :

git pull origin master is it the same as git pull master and git pull? and why?

Thank you so much for your response.


Solution

  • git pull origin master is telling git to pull from the master branch of the remote called origin.

    Doing just git pull will pull in changes from all the branches of the default remote i.e. origin. git pull is equivalent to git pull origin by default.

    When using git pull from any checked out branch, you first need to tell git what remote and which branch you mean to pull from (again, by default the remote is origin).

    In git's terminology it is called setting up the remote tracking branch for your locally checked out branch and you do so by running below command,

    git branch --set-upstream-to=origin/master

    Considering your currently checked out branch is master, then the above command tells git to tie the master branch of local with the master branch of remote.

    Once you have set up your local master(or any other branch) branch to track the remote branch master from origin, you can then perform just git pull and git would be smart enough to understand that it has to fetch in changes from origin/master and merge to master of local.

    You can also combine the task of setting up remote tracking branch and pulling in changes from the tracking branch into one single command,

    git pull --set-upstream origin master

    OR

    git pull -u origin master

    You can always replace origin with any other remote of your interest, likewise master with any other branch. Origin is just the git's way of providing default name for remote which usually points to the original repo that you cloned from.

    You can check the configured remotes by,

    git remote -v

    You also mentioned about git pull master. This is not a valid command. The general syntax of a git pull command is : git pull [<options>] [<repository> [<refspec>…​]]