Git pull Command
In this page:
What is Git Pull?
git pull is shorthand for two operations in sequence: it fetches new commits from a remote, then immediately merges them into your currently checked-out branch, updating your working files in the same step.
Example: What is Git Pull?
git pull origin main
How Git Pull Works
Under the hood, git pull first updates your remote-tracking branch (like origin/main) to match the server, then runs a normal merge between that updated reference and your local branch.
Example: How Git Pull Works
git fetch origin
git merge origin/main
Pulling with Rebase
By default that merge step creates a merge commit if histories have diverged; git pull --rebase replaces the merge with a rebase instead, keeping your project's history linear rather than branching at every sync.
Example: Pulling with Rebase
git pull --rebase origin main
Pulling a Specific Branch from Remote
git pull origin <branch> lets you pull any branch directly into your local database, not just whatever branch you currently have checked out -- useful for grabbing a teammate's branch without switching to it first. Running git pull origin <branch> when no local branch of that name exists yet still requires checking out a local branch tracking it first -- git checkout --track origin/<branch> (or git switch -c <branch> origin/<branch>) creates that local branch, and a plain git pull afterward keeps it updated with the remote branch's latest commits.
Example: Pulling a Specific Branch from Remote
git pull origin feature-x
Handling Pull Conflicts
If your local uncommitted changes conflict with incoming remote changes, git pull pauses with an error rather than silently overwriting anything -- you'll need to commit, stash, or discard your local changes before the pull can proceed.
Example: Handling Pull Conflicts
git pull origin main
# error: local changes would be overwritten
git stash
git pull origin main
Chapter Quiz — Complete all 11 topics to unlock
0/11 topics done
Complete these topics first: