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?
'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.
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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With