Remote Git Repositories | git pull
The git pull command
Merging changes from a central repository into a local repository is a common task in Git-based collaboration workflows. You can do this with git fetch followed by git merge, as explained earlier. git pull is a shortcut that runs those two commands together.
Usage
git pull <remote>
Fetches a copy of the current branch from the specified remote and immediately merges it into the current branch. This is equivalent to running git fetch <remote> and then git merge origin/<current-branch>.
git pull --rebase <remote>
Similar to the command above, but uses git rebase when integrating the remote branch into the current branch.
Additional notes
You can think of git pull as the Git equivalent of SVN’s svn update. It is a convenient way to synchronize a local repository with a central repository.
Git Tutorial: git pull
Suppose the local repository was initially synchronized with origin. After running git fetch, Git discovers that origin/master has moved forward since the last check. Running git merge then merges the remote master into the local master.
Pulling with rebase
The --rebase flag is used to preserve linear history and reduce merge commits. Rebase is equivalent to saying, “I want all of my work to be based on the latest completed changes.” Many developers prefer rebase to merge. In that sense, git pull --rebase is closer to SVN’s svn update than a plain git pull.
Because pulling with --rebase is a common workflow, Git provides a configuration command for it:
git config --global branch.autosetuprebase always
After running this command, future git pull commands use git rebase instead of git merge during integration.
Example
The following example shows how to synchronize with the central repository’s master branch:
git checkout master
git pull --rebase origin
After this command, your local changes are placed on top of all work from other developers.