Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between 'git pull' and 'git pull origin master'? [duplicate]

Tags:

git

What is the difference between git pull and git pull origin master?

What if I am on a branch other than master, will the two commands achieve a different result?

like image 761
kgbph Avatar asked Aug 31 '18 05:08

kgbph


People also ask

What does git pull origin master mean?

'git pull origin master' will fetch and update only a specific branch called master and origin in the remote repository. Often, the default branch in Git is a master branch, and it keeps updating frequently. A user can use any branch name to pull that branch from the remote.

What is the difference between git pull and git merge?

A Git pull request is essentially the same as a Git merge request. Both requests achieve the same result: merging a developer's branch with the project's master or main branch. Their difference lies in which site they are used; GitHub uses the Git pull request, and GitLab uses the Git merge request.

What is the difference between master and origin master?

Master: This is a branch name where we first initiate git and then we use to make commits. And the changes in the master can pull/push into a remote. origin/master: This is a remote branch, which has a local branch named master on a remote named origin.

What is difference between git pull git clone and git fetch?

Git Fetch is the command that tells the local repository that there are changes available in the remote repository without bringing the changes into the local repository. Git Pull on the other hand brings the copy of the remote directory changes into the local repository.


2 Answers

Remember, a pull is a fetch and a merge.

  • git pull origin master fetches commits from the master branch of the origin remote (into the local origin/master branch), and then it merges origin/master into the branch you currently have checked out.

  • git pull only works if the branch you have checked out is tracking an upstream branch. For example, if the branch you have checked out tracks origin/master, git pull is equivalent to git pull origin master

like image 71
Naga Avatar answered Sep 17 '22 18:09

Naga


First, let us understand what git pull is:

  • The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content. The git pull command is a combination of git fetch and git merge. git pull will download the content from the remote repository. Once the content is downloaded, git merge will merge the content to your local repository. A new merge commit will be created and HEAD updated to point at the new commit.

  • Now that we know what git pull does, when we do git pull origin master, it simply fetches a copy of the master branch from the original repository, and merges it with the current branch that you have checked out.

For more information, you can go to this link.

like image 36
Sana Jahan Avatar answered Sep 19 '22 18:09

Sana Jahan