Git Pull: Sync Your Branch with the Remote
git pull keeps your local branch in sync with the remote. This tutorial explains what pull actually does (fetch + merge or rebase), when to prefer git fetch, and how to handle conflicts that arise during a pull.
Beginner8 min readUpdated
What is git pull?
git pull is a shortcut for git fetch followed by git merge (or git rebase). It downloads new commits from the remote and integrates them into your current local branch.
The short version
- 1Commit or stash local changes first
- 2Run
git pullto fetch and merge - 3Or
git pull --rebasefor a linear history - 4If conflicts occur: resolve,
git add,git commit
Why it matters
A teammate pushed new commits. You run git pull and end up with a merge commit in your history that you didn't expect, or worse, a conflict that you don't know how to handle.
git pull is how you stay in sync with your team. But it does more than just download code: it also merges (or rebases) the remote changes into your local branch. Understanding what it does under the hood saves you from unexpected merge commits and conflicts.
Where it usually goes wrong
- Running
git pullwithout understanding it also merges - Getting a merge conflict on pull and not knowing how to resolve it
- Pulling into a dirty working directory with uncommitted changes
- Not knowing the difference between
git pullandgit fetch
Git pull, step by step
Step 1: Pull the latest changes from origin
The simplest use: update your current branch from its tracked remote branch.
Terminalgit pullTip: Make sure you're on the right branch before pulling. Run
git branchto confirm.Step 2: Pull from a specific remote and branch
Explicitly specify remote and branch when you want to pull from something other than the default.
Terminalgit pull origin mainStep 3: Pull with rebase instead of merge
By default,
git pullcreates a merge commit. Using--rebasere-applies your local commits on top of the incoming ones, giving you a linear history.Terminalgit pull --rebase origin mainTip: Set rebase as the default pull strategy:
git config --global pull.rebase trueStep 4: Fetch first, then review before merging
If you want to see what's on the remote before integrating it, use
git fetchand inspect the diff first.Terminalgit fetch origin# See what's new on the remotegit log origin/main..HEAD # your local commits not on remotegit log HEAD..origin/main # remote commits not on your local# Now merge when readygit merge origin/mainIn Gitoryx: See how many commits you're behind origin at a glanceHow it works Step 5: Handle a conflict during pull
If there's a conflict, Git pauses the merge and marks the conflicted files. Resolve them, stage the files, then complete the merge.
Terminalgit pull# CONFLICT (content): Merge conflict in src/app.ts# Edit the file to resolve the conflict, then:git add src/app.tsgit commitCareful: Don't run
git pullwith uncommitted changes: Git may refuse or produce unexpected results. Commit or stash first.Step 6: Abort a pull mid-conflict
Changed your mind? You can abort the in-progress merge and return to the pre-pull state.
Terminalgit merge --abort
Mistakes to avoid with git pull
- Pulling with uncommitted local changes
- Git may refuse the pull, or partially apply changes leading to a confusing state.
- Fix: Commit your work or stash it (
git stash) before pulling. - Accumulating merge commits from `git pull`
- Every pull creates a 'Merge branch main of origin/main' commit, cluttering the history.
- Fix: Use
git pull --rebaseto integrate remote changes without merge commits. - Confusing `git fetch` with `git pull`
git fetchis safe: it only updates remote tracking branches.git pullfetches AND integrates, potentially creating conflicts.- Fix: Use
git fetchwhen you want to inspect changes first,git pullwhen you're ready to integrate.
Git pull in Gitoryx
Gitoryx shows you exactly how far your branch is behind origin before you pull, and lets you choose to pull with merge or rebase from the toolbar.
- See how many commits you're behind origin at a glance
- One-click pull with merge or rebase option in the toolbar
- Visual conflict resolution when a pull triggers a conflict
- Fetch all remotes with a single button: inspect before merging
Free plan · no account required · macOS, Windows and Linux
Git pull: frequently asked questions
- What is the difference between `git pull` and `git fetch`?
git fetchdownloads remote changes and updates remote tracking branches (likeorigin/main) but does not touch your local branch.git pulldoes a fetch then automatically merges (or rebases) into your current branch.- How do I pull without creating a merge commit?
- Use
git pull --rebase. This re-applies your local commits on top of the remote commits, resulting in a linear history with no merge commit. - What should I do if `git pull` causes a conflict?
- Open the conflicted files, resolve the conflict markers (
<<<<<<<,=======,>>>>>>>), stage the resolved files withgit add, and then rungit committo complete the merge. - Can I pull a branch I'm not currently on?
- Not directly. You need to switch to that branch first, then pull. Alternatively, use
git fetchto update the remote tracking branch without switching.
Related reading
- Git Remote: Connect Your Repo to a Remote ServerTutorial · 8 min
- How to Resolve Merge Conflicts in GitTutorial · 12 min