Skip to main content

Git Pull

Updated 3 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/git-pull

In short

Git pull is a Git command that downloads new commits from a remote repository and immediately integrates them into your current local branch.

What is git pull?

git pull updates your current branch with work that others have pushed to the remote repository. It is really two commands in one: git fetch, which downloads new commits and updates remote-tracking branches such as origin/main, followed by a step that combines those commits with your local branch. Developers typically pull before starting new work and before pushing, so their branch is based on the latest code.

How the combining step works depends on the situation and your settings. If you have no local commits of your own, Git simply fast-forwards your branch to match the remote. If both sides have new commits, git pull either merges them, creating a merge commit, or, with git pull --rebase, replays your local commits on top of the remote ones. When the branches have diverged and no preference is configured, modern versions of Git stop and ask you to choose by setting pull.rebase or pull.ff.

Pulling is like syncing a shared calendar before adding your own appointments: you first see what everyone else has booked, then fit your plans around it. Because the integration step can hit the same conflicts as any merge or rebase, pulling small and often keeps conflicts rare and easy to resolve. The cautious git pull --ff-only updates your branch only when no merge is needed and otherwise stops so you can decide.

The most common confusion is git pull versus git fetch. Fetch only downloads new commits and never touches your files or branches, so it is always safe to run, while pull goes on to change your current branch. Despite the name, git pull is also unrelated to a pull request: a pull request is a hosting platform feature for asking others to review and merge your branch, while git pull brings other people's commits into yours.

Key takeaways

  • git pull runs git fetch and then merges or rebases the result into your current branch.
  • It fast-forwards when you have no local commits of your own.
  • git pull --rebase replays your local commits on top of the remote ones instead of creating a merge commit.
  • git fetch is the download-only alternative that never changes your working files.
  • Pulling can cause merge conflicts, which you resolve like any other merge.

Example

Pulling changes from a remotebash
# Update the current branch from its upstream branch
git pull

# Roughly the same as these two steps (when on main):
git fetch origin
git merge origin/main

# Replay local commits on top of the remote ones instead of merging
git pull --rebase

# Only update if no merge is needed (never creates a merge commit)
git pull --ff-only

# Set a default once so Git doesn't have to ask
git config --global pull.rebase true

Readers ask

What is the difference between git fetch and git pull?

git fetch downloads new commits from a remote and updates remote-tracking branches like origin/main, but leaves your own branches and files alone. git pull does the same fetch and then merges or rebases those commits into your current branch.

Should I use git pull --rebase?

Many teams prefer it for syncing a personal branch, because it keeps history linear without extra merge commits. Avoid it if your local commits have already been shared with others, since rebasing rewrites them.

How do I undo a git pull?

Right after the pull, git reset --hard ORIG_HEAD moves the branch back to where it was before, discarding the pulled changes. Make sure you have no uncommitted work first, because --hard also throws that away.

Often compared

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings