git pull

Sharing and Updating

Fetch from and integrate with another repository or a local branch


The 'git pull' command fetches content from a remote repository and immediately integrates it into your local branch. It's essentially a combination of 'git fetch' followed by 'git merge' (or 'git rebase' with --rebase flag). This is the most common way to synchronize your local repository with changes made by others. When you run git pull, Git first downloads all new commits from the remote, then integrates them into your current branch. If your branch is simply behind, it fast-forwards; if both sides have new commits, modern Git stops and asks you to choose merge or rebase (--no-rebase / --rebase, or the pull.rebase setting). If there are conflicting changes, Git will pause and ask you to resolve the conflicts before completing the merge.

Synopsis

git pull [--rebase | --no-rebase] [--ff-only | --ff | --no-ff] [--commit | --no-commit] [--autostash | --no-autostash] [-q | --quiet] [-v | --verbose] [--depth=<depth>] [--prune] [--tags | --no-tags] [--recurse-submodules[=yes|on-demand|no]] [<repository> [<refspec>...]]
[ ] optional| or<arg> placeholder... repeatable--flag option

Options

Click any option to expand

Beginner (7)

The default remote repository name. When you clone a repository, Git automatically names the remote 'origin'. You can pull from origin by specifying it explicitly or rely on the default tracking configuration.

When neededNames the remote/branch explicitly; plain git pull uses the upstream

Example

git pull origin main

Rebase the current branch on top of the upstream branch after fetching. This creates a linear history by replaying your local commits on top of the fetched commits, avoiding merge commits.

RecommendedReplays your unpushed commits on top, keeping history linear

Example

git pull --rebase origin main

Shorthand for --rebase=false. Overrides any configuration that defaults to rebasing and forces a merge instead of rebase when integrating fetched changes. Creates a merge commit if histories have diverged.

When neededExplicitly merge when branches diverged or config defaults to rebase

Example

git pull --no-rebase origin main

Only update if the local branch can be fast-forwarded (no local commits ahead of remote). Fails if histories have diverged, preventing accidental merges and prompting you to decide how to integrate.

RecommendedNever creates surprise merges; stops so you choose when branches diverge

Example

git pull --ff-only origin main

Be verbose. Shows detailed information about the fetch and merge operations, including which refs are being updated and object transfer statistics.

When neededFor debugging what fetch and merge are doing

Example

git pull -v origin main

Suppress output during fetch and merge operations. Only errors are shown. Useful in scripts where you want silent operation.

When neededFor scripts; hides progress and merge output

Example

git pull -q origin main

Automatically stash local modifications before pulling and reapply them after the pull is complete (works with both merge and rebase pulls; if reapplying conflicts, your changes stay safe in the stash). Perfect when you have uncommitted changes but need to sync with remote.

When neededConvenient with uncommitted work; a re-apply conflict leaves it in the stash

Example

git pull --rebase --autostash origin main

Intermediate (6)

Perform the merge but stop before creating the merge commit. Allows you to inspect and potentially modify the merge result before committing.

When neededStops before the merge commit so you can inspect the result

Example

git pull --no-commit origin main

Before fetching, remove any remote-tracking references that no longer exist on the remote. Helps keep your local repository clean from stale branches. Only prunes when the remote's configured refspecs are used - 'git pull --prune origin main' prunes nothing.

When neededCleans stale remote-tracking refs; does nothing with an explicit refspec

Example

git pull --prune

Fetch all tags from the remote in addition to whatever else would normally be fetched. Useful for syncing release tags.

When neededAlso fetches tags not on the pulled history; rarely needed

Example

git pull --tags origin main

Disable automatic tag following: by default, tags pointing at downloaded commits are fetched too. Overrides the remote.<name>.tagOpt setting. Useful when you only want branch updates.

When neededSkips automatic tag following for branch-only updates

Example

git pull --no-tags origin main

Limit fetching to the specified number of commits from the tip of each remote branch history. Creates or deepens a shallow clone. Useful for large repositories.

When neededKeeps a shallow clone shallow (CI); history-based commands see less

Example

git pull --depth=1 origin main

Fetch all remotes. Instead of pulling from a single remote, this fetches from all configured remotes before merging.

When neededFetches every remote but still merges only the current upstream

Example

git pull --all

Advanced (4)

Control whether submodules are recursively fetched and updated. Values: 'yes' (always), 'on-demand' (when superproject updates submodule ref), 'no' (never).

When neededOnly in repos with submodules, to keep them in sync

Example

git pull --recurse-submodules=on-demand origin main

Convert a shallow repository to a complete one by fetching all missing history. Only valid when pulling into a shallow clone.

When neededTurns a shallow clone into a full one when you need all history

Example

git pull --unshallow origin main

Use the specified merge strategy. Common strategies: ort (the default), resolve, octopus, ours, subtree. recursive is still accepted but is only a synonym for ort since Git 2.50.

When neededRarely needed; the default ort strategy fits almost every pull

Example

git pull -s ort origin main

Allow merging histories that do not share a common ancestor. Required when combining two repositories that were created independently.

Not recommendedOnly for deliberately joining separate repos; otherwise hides a mistake

Example

git pull --allow-unrelated-histories origin main

Choosing the Right Option

Pull Strategy: Merge vs Rebase

The fundamental choice that affects your commit history

CommandCreates Merge CommitHistory StyleBest For
git pullDepends on config (fails if diverged and unset)Set by pull.rebase / pull.ffFast-forward when only behind
git pull --rebaseNoLinearFeature branches, clean history
git pull --no-rebaseYes (if diverged)Preserves branchesOverride rebase config, force merge
git pull --ff-onlyNoLinear (fails if diverged)Ensuring no accidental merges

Safety & Control Options

Options to prevent mistakes and maintain control

CommandPreventsBehaviorWhen to Use
--ff-onlyUnexpected mergesFails if can't fast-forwardCI/CD, protected branches
--no-commitAuto-commitMerges but stops before commitReview merge before committing
--autostashDirty workdir errorsStash → pull → popQuick sync with uncommitted work
--dry-runAny changesShows what fetch would download; no mergePreview incoming refs

What Gets Fetched

Control which refs and history are downloaded

CommandFetches TagsFetches Full HistoryUse Case
git pullAuto (followed tags)YesNormal workflow
--tagsAll tagsYesSync release versions
--no-tagsNoYesSave bandwidth, branch-only sync
--depth=NAuto (followed tags)Last N commits onlyLarge repos, CI builds
--unshallowAuto (followed tags)Converts shallow to fullNeed full history after shallow clone

Remote & Branch Management

Options for handling multiple remotes and stale refs

CommandScopeCleans UpScenario
git pull origin mainSingle remote/branchNoStandard pull from origin
--allAll remotesNoSync from origin + upstream
--pruneSingle remoteDeleted branchesRemove stale tracking refs

Advanced Scenarios

Options for complex or unusual situations

CommandSolvesRisk LevelTypical Scenario
--allow-unrelated-historiesNo common ancestorMediumMerging two separate repos
-s <strategy>Special merge needs (does not avoid conflicts)LowForce specific merge algorithm
--recurse-submodulesOutdated submodulesLowProjects with git submodules

Workflow Examples

1
git status

Check for uncommitted changes that might conflict

2
git stash

Stash any uncommitted work if needed (or use --autostash)

3
git pull --rebase origin main

Pull with rebase to keep history clean

4
git stash pop

Restore your stashed work if you stashed earlier

1
git checkout feature-branch

Switch to your feature branch

2
git pull --no-rebase origin main

Merge the latest main into your feature branch (explicit, since the branches have diverged)

3
git push origin feature-branch

Push the updated feature branch

1
git fetch origin

Download remote changes without modifying working directory

2
git log HEAD..origin/main

See what commits you're about to pull

3
git diff HEAD...origin/main

Review the changes made on the remote

4
git pull origin main

Pull once you're satisfied with the changes

1
git pull --no-rebase origin main

Attempt a merge pull - may result in conflicts

2
git status

See which files have conflicts (marked as 'both modified')

3
(edit conflicted files)

Open files and resolve conflict markers (<<<<<<<, =======, >>>>>>>)

4
git add <resolved-files>

Stage the resolved files

5
git commit

Complete the merge with a commit

1
git pull --rebase --autostash origin main

Automatically stash changes, pull, then reapply them

Troubleshooting

Your local changes would be overwritten by merge

Cause: You have uncommitted changes in files that the pull would modify

Commit your changes first (git add . && git commit), stash them (git stash), or use git pull --rebase --autostash

git stash && git pull && git stash pop

Refusing to merge unrelated histories

Cause: The remote and local repositories have no common ancestor (e.g., pulling into a newly initialized repo)

Allow unrelated histories to merge, which is common when adding a remote to an existing local repo

git pull --allow-unrelated-histories origin main

Merge conflict in file(s)

Cause: Both you and the remote made changes to the same lines in a file

Open conflicted files, look for markers (<<<<<<<, =======, >>>>>>>), edit to resolve, then git add and git commit. Or abort with git merge --abort

git add <resolved-file> && git commit

Not possible to fast-forward, aborting

Cause: You used --ff-only (or pull.ff=only is set) but your local branch has diverged from remote

Use rebase instead (git pull --rebase) or allow a merge commit (git pull --no-rebase)

git pull --rebase origin main

Cannot pull with rebase: You have unstaged changes

Cause: A rebase pull needs a clean working tree, and you have uncommitted modifications

Commit or stash your changes, or use autostash to automatically handle them

git pull --rebase --autostash

No tracking information for the current branch

Cause: Your branch isn't set up to track a remote branch

Set the upstream branch explicitly, or specify the remote and branch in the pull command

git branch --set-upstream-to=origin/main main

'origin' does not appear to be a git repository

Cause: No remote named 'origin' is configured

Check your remotes with git remote -v and either add origin or use the correct remote name

git remote add origin <url>

You have divergent branches and need to specify how to reconcile them

Cause: Both sides have new commits and neither pull.rebase nor pull.ff is set, so modern Git refuses to guess (older 2.27+ only warned)

Specify merge (--no-rebase) or rebase (--rebase), or configure a default with git config pull.rebase

git config --global pull.rebase true

Tips & Pitfalls

Best Practices

  • ✓Always check git status before pulling to avoid conflicts with uncommitted changes
  • ✓Use git pull --rebase to maintain a clean, linear commit history on feature branches
  • ✓Configure pull.rebase=true globally if you prefer rebase by default: git config --global pull.rebase true
  • ✓Use git fetch first when you want to review changes before integrating them
  • ✓Use --ff-only when you want to ensure no merge commits are created accidentally
  • ✓Set up branch tracking with git push -u on first push to simplify future pulls
  • ✓Use --autostash when you have uncommitted changes but need to pull quickly
  • ✓Pull from main/master regularly to avoid large, complex merges later
  • ✓Resolve conflicts immediately - never leave your repository in a conflicted state
  • ✓Use git pull --prune to clean up stale remote-tracking branches
  • ✓Consider using git fetch + git merge for more control over the integration process
  • ✓Always verify you're on the correct branch before pulling to avoid mixing changes

Common Mistakes

  • ✗Pulling with uncommitted changes: This can cause merge conflicts or fail entirely. Always commit or stash your changes first, or use --autostash to automatically handle this.
  • ✗Not understanding pull vs fetch: 'git pull' automatically merges, which can be surprising. Use 'git fetch' first if you want to review changes before integrating them.
  • ✗Using merge when rebase is cleaner: On feature branches, 'git pull --rebase' creates a cleaner linear history without unnecessary merge commits.
  • ✗Ignoring merge conflicts: After a pull with conflicts, you must resolve them and commit. Never leave your repository in a conflicted state.
  • ✗Pulling into the wrong branch: Always check your current branch with 'git status' before pulling. Pulling into main when you meant to pull into a feature branch can cause issues.

FAQ

A:

git fetch only downloads new commits from the remote without modifying your working directory or local branches. git pull does fetch AND automatically merges (or rebases) those changes into your current branch. Use fetch when you want to review changes before integrating them.

A:

Use --rebase when you want a clean, linear history (especially on feature branches). This replays your local commits on top of the fetched commits instead of creating a merge commit. Use regular pull (merge) when you want to preserve the exact history of when changes were made.

A:

Fast-forward happens when your local branch has no new commits that the remote doesn't have. Git simply moves your branch pointer forward to match the remote - no merge commit is needed. If you have local commits, Git must either create a merge commit or rebase - and unless you pass --rebase/--no-rebase or set pull.rebase, modern Git stops with 'Need to specify how to reconcile divergent branches'.

A:

Use git pull --rebase to replay your local commits on top of the remote commits, creating a linear history. Or use git pull --ff-only which will only succeed if a fast-forward is possible (fails if you have local commits ahead).

A:

It depends. With a merge pull, Git allows it if the incoming commits don't touch the files you modified; otherwise it refuses with 'Your local changes ... would be overwritten by merge'. With --rebase, any uncommitted change blocks the pull. Best practice: commit your changes first, or use git pull --rebase --autostash to automatically stash and restore your changes.

A:

Git will pause the merge and mark conflicted files. Open each conflicted file, look for conflict markers (<<<<<<<, =======, >>>>>>>), edit to resolve, then git add the file and git commit to complete the merge. Use git merge --abort to cancel (or, for git pull --rebase, git rebase --continue / git rebase --abort).

A:

Right after the pull, run git reset --hard ORIG_HEAD - Git saves your previous tip in ORIG_HEAD for merges, fast-forwards and rebases. Don't use HEAD~1: a fast-forward may have brought several commits. --hard also discards uncommitted changes. If ORIG_HEAD has moved since, find the old tip with git reflog.

A:

This usually means you're pulling from the wrong branch or remote. Check: git branch -vv to see tracking info, git remote -v to verify remotes, and git fetch --all followed by git log origin/main to see remote commits.

A:

git pull origin main explicitly specifies the remote and branch to pull from. git pull (no arguments) uses the tracking branch configured for your current branch. If tracking isn't set up, you'll get an error asking you to specify.

A:

Set globally: git config --global pull.rebase true (for rebase) or git config --global pull.rebase false (for merge). You can also set per-repository without --global, or per-branch with git config branch.<name>.rebase true.