Git & version control

Git Pull

Learn the git pull command, compare fast-forward, merge and rebase, and build the command you need. Explore how each option changes a sample commit history.

See what your pull will doA local illustration. No repository is connected.
Your command
git pull --ff-only origin main

This integrates the selected remote branch into whichever local branch you currently have checked out. It does not switch branches.

Before the pull
After the pull
Local work Remote work Merge commit
Choose a history and strategy to see the outcome.

What does git pull do?

git pull fetches commits from another repository, then integrates a selected branch into your current local branch. Without an explicit remote and branch, Git normally uses the current branch’s configured upstream.

The integration can be a fast-forward, a merge or a rebase, depending on your flags and configuration. Using an explicit flag makes your intention clear across Git versions and repository settings.

Command syntax
git pull [options] [remote] [branch]
  1. Open a terminal inside your local repository.
  2. Run git status and confirm you are on the branch you want to update. Commit or stash unfinished changes if they would interfere.
  3. Run a pull command with the integration strategy you intend.
  4. Resolve any conflicts, then run your project’s usual checks.

Choose a pull strategy

OptionBehaviorWhen it fits
--ff-onlyMoves the branch forward only when no divergent local history needs combining. Otherwise it stops.Updating a branch when you expect no local-only commits.
--no-rebase --ffFast-forwards when possible; otherwise combines the histories with a merge commit.Keeping the existing identity and branching structure of commits.
--rebaseReplays local-only commits on top of the fetched branch.Maintaining a linear history when your team’s workflow permits rewriting those local commits.

The simulator assumes a clean working tree and no content conflicts. A real merge or rebase may stop for conflicts even when the histories can be combined.

Git pull examples

Update without a merge

Fetch remote main and move the current branch forward only if it has not diverged.

git pull --ff-only origin main

Rebase local work

Replay local commits after the remote branch. This changes the IDs of the replayed commits.

git pull --rebase origin main

Allow a merge

Keep existing commit IDs. The explicit fast-forward option permits a fast-forward where possible.

git pull --no-rebase --ff origin main

Inspect before integrating

Fetch first, then compare the current branch with the fetched remote branch before choosing your next step.

git fetch origin
git log --oneline --graph HEAD..origin/main

Pull, fetch, clone and push

CommandPurpose
git cloneCreate a local copy of a repository and set up its remote.
git fetchDownload remote history and update remote-tracking references without integrating it into your current branch.
git pullFetch and integrate a selected remote branch into your current branch.
git pushSend local commits to update a remote branch.

Common questions

Does git pull origin main switch me to main?

No. It integrates the remote’s main branch into the local branch you currently have checked out. If you mean to update local main, switch to it first after checking your working tree.

Why does Git say it cannot fast-forward?

Your current branch and the fetched branch have diverged. Inspect the changes and follow your team’s merge or rebase policy. A fast-forward-only pull intentionally refuses to choose a way to combine those histories for you.

How do I handle a pull conflict?

Use git status to see the affected files. Resolve their conflicting changes, stage the resolutions and continue the merge or rebase as Git instructs. To cancel an in-progress merge, use git merge --abort; for a rebase, use git rebase --abort. Start with a clean working tree so there is less unrelated work to recover.

Should I use merge or rebase?

Follow the repository’s workflow. Merge preserves the existing histories. Rebase produces a linear sequence by rewriting local-only commits. Coordinate before rebasing commits that other people already depend on.

Why does git pull behave differently in another repository?

Git version, upstream configuration and settings such as pull.rebase and pull.ff can affect the behavior. The current Git manual describes fast-forward-only as the default; older versions and configured repositories can differ. Use explicit flags when you want a predictable strategy.

Does this page run commands on my repository?

No. The builder creates copyable commands and the diagram explains sample histories. It does not connect to GitHub, access your files or execute Git.