Git pull is a command that can be executed to download the last changes in the remote branch to the local branch of the project.

In other words, if the local branch behind the remote branch, it will directly update the local branch to be match with the remote branch.

Git pull command would be like the below.

git pull origin [BRANCH-NAME]

As you see, the git pull command has three parts.

  • git pull refers to the main pull command to withdraw the latest changes from the online repository.
  • origin is the name of the remote repository that allows users to clone from.
  • [BRANCH-NAME] defines another line in the development stack; the thing like another direction that contains a new pointer in the stack.

So by default, you have to use the master as a branch name, if you have no a specific name. It would be like the below command.

git pull origin master

Let’s understand how it works.

How Does Git Pull Work Behind the Scene?

The git pull runs two commands else behind the scene to download the changes from the remote branch into the local branch.

Git Pull Command

For manually, the online branch can be downloaded to the local branch using two commands: git fetch and (git merge or git rebase).

These two commands are doing two tasks, which are:

  • Fetching the changed data from the remote branch (the online branch or the remote server) and that can be done using the git fetch.
  • Merging the downloaded changes with the current branch (the local branch). And that can be done using: git merge or git rebase.

And to run the git pull manually you have to use the fetch and merge commands as I mentioned before.

git fetch

Then merge the downloaded changes by the below command.

git merge origin

Simple Story for Git Pull

Sane and Jemmy are web developers, they are working on a web application, each other working from another country.

So, they decided to use the GIT version control system and GitHub to track and manage their project.

In some day, Sane uploaded some changes from his local branch into the remote branch and the change was in the JavaScript file.

But, he didn’t tell Jemmy with this change!

In the following day, Jemmy opened his version in the local branch that already located on his computer.

But, jemmy had no idea about the change of the Sane until he executed the git pull command.

He saw the data changed and the file name in the git bash CMD during the fetching of the data from the online branch.

By using this command, he downloaded the latest change from the online branch and merges it with his local branch.

Wrapping Up

Git pull is a command to download the latest change from the online branch into the local branch, and that can be done by two commands behind the scene: git fetch and git merge.

That’s all, thank you for reading.