linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
Intro
Lessons
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Chapters
  • How it works
  • Lessons
  • Knowledge base
  • Interview prep
home/git/kb/Remote repositories/pull

kb/remote ── Remote repositories ── beginner

git pull

Fetches updates from a remote repository and merges them into the current branch. Essentially `git fetch` + `git merge` (or + `git rebase` with `--rebase`). The most confusing command for beginners.

view as markdownaka: git-pull

git pull is a compact wrapper around two operations. By default it runs fetch (download updates) and then merge (merge into the current branch).

pull or fetch + merge?

Technically git pull = git fetch && git merge FETCH_HEAD. Many developers prefer to do these steps separately:

  • git fetch to see what arrived without touching the local branch.
  • git log origin/main..main to check the difference.
  • git merge or git rebase to integrate deliberately.

This gives you a pause between "got data" and "changed local branch." Useful on complex repositories.

--rebase vs merge

By default pull does a merge. The alternative is rebase:

bash
git pull --rebase

This fetches the remote commits, then rewrites your local commits as if you had made them on top of the fresh remote ones. History stays linear, with no merge commits.

Which is better is a debate of decades. A practical rule:

  • rebase for your own feature branch before sharing it.
  • merge for shared branches (main, master).
  • Set the default with config: git config --global pull.rebase true.

Without an explicit setting, Git 2.27+ warns about strategy ambiguity on every git pull. The pull still works (merge), but the warning is there to make you choose deliberately. Set pull.rebase or pull.ff in config and the warning goes away.

--ff-only

The safest option:

bash
git pull --ff-only

Fetches updates only if fast-forward is possible. If you have local commits that are not merged, it refuses and you resolve it manually (merge or rebase). This prevents accidental merge commits from habit.

What physically happens

  1. git fetch origin downloads all new objects into .git/objects/ and updates origin/<branches> (these are refs/remotes/origin/...).
  2. Takes the remote tracking branch (origin/main) and compares it with the local one (main).
  3. Runs merge (or rebase) of FETCH_HEAD into the current branch.

Local history is written only in step 3. Before that, git fetch can be called as many times as you want. It is safe.

Pitfalls

  • git pull with unstaged changes in files the remote also modifies will fail with an error. Fix: stash before pull, or commit first.
  • Without a tracking branch, git pull with no arguments does not work. You need to be explicit: git pull origin main.
  • git pull --rebase on a branch with already-pushed commits rewrites their SHAs. The next push will require --force-with-lease. Do not do this on branches other people are looking at.

§ команды

bash
git pull

fetch + merge (or rebase, depending on config)

bash
git pull --rebase

Fetch remote commits and rewrite local ones on top

bash
git pull --ff-only

Fast-forward only; refuse on divergence

bash
git fetch && git merge origin/main

Equivalent to pull, but lets you inspect before merging

§ см. также

  • pushgit pushSends local commits to a remote repository and updates the branch there. If the remote received commits from someone else after your last pull, push will refuse until you synchronize.
  • mergegit mergeMerges another branch into the current one. Either fast-forwards the pointer or creates a merge commit with two parents. Overlapping changes produce conflicts.
  • branchBranchA branch in Git is a file inside `.git/refs/heads/` that holds the SHA of one commit. Creating, switching, and deleting branches are trivial operations because a branch contains exactly 41 bytes of data.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies