git pull <remote>
This command is useful for keeping your local branch up to date with changes from a remote repository by automatically fetching and merging new commits.
It operates by first downloading the latest changes from the specified remote, then immediately merging them into your current branch, so you get both steps in one command.
You can use this command with different remotes, such as git pull origin
or git pull upstream
, depending on which remote you want to sync with. Adding a branch name, like git pull origin main
, will fetch and merge a specific branch.
The --rebase
flag can be used as a variation to rebase your changes on top of the fetched commits instead of merging, which can help keep your history linear.
Closely related commands include git fetch <remote>
, which only downloads changes without merging, and git merge <branch>
, which merges a branch into your current branch after you have fetched updates separately. Using git pull
is a shortcut for combining these two steps.