0

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.

phd
  • 82,685
  • 13
  • 120
  • 165
  • Not sure of what `git pull master` does... `pull` is not usually used for local actions. Use `merge` instead. Additionnaly, you can use `remotes/origin/branch_name`, which points to the local reference you have for the branch _branch_name_, but then the `HEAD` of that branch can at a different state than the one on the remote `origin`. Git is full of tricks ! – St3an Apr 02 '21 at 10:51
  • Another interesting post could help too, for comprehension : https://stackoverflow.com/questions/33402589/does-a-git-pull-update-all-tracked-branches – St3an Apr 02 '21 at 11:03
  • Okay, thank you so much – Yahya Mallak Apr 02 '21 at 11:44

2 Answers2

1

origin is the remote you pull from. master is the branch.

If you omit the remote and the branch, git uses a default. You can inspect the defaults for each branch with git branch -avv.

git pull master is not a valid command unless master is a remote.

timgeb
  • 76,762
  • 20
  • 123
  • 145
1

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>…​]]

Asif Kamran Malick
  • 2,409
  • 3
  • 25
  • 47