sync
git pull
Fetches from the remote and integrates the changes into the current branch, effectively 'git fetch' followed by 'git merge' (or rebase). Updates your working tree with upstream commits.
git pull [<remote> [<branch>]] Common flags
| Flag | Purpose |
|---|---|
| --rebase | Rebase local commits on top of fetched work instead of merging |
| --ff-only | Refuse to pull unless a fast-forward is possible |
| --no-rebase | Force a merge even if pull.rebase is configured |
| --autostash | Stash and reapply local changes around the pull |
| --prune | Remove remote-tracking refs that no longer exist upstream |
Examples
git pull Pull from the tracked upstream branch
git pull --rebase origin main Rebase local commits on top of origin/main
git pull --ff-only Only accept fast-forward updates, no merge commits
Gotcha
Default merge behavior creates unnecessary merge commits; setting 'pull.rebase = true' or using --ff-only keeps history linear.
Related commands
git fetch
Downloads objects and refs from a remote without modifying your working tree or current branch. Safest way to see what's new upstream before integrating.
git push
Uploads local commits from a branch to a remote repository, updating the remote-tracking references. Requires push permission on the remote.
git merge
Joins the history of another branch into the current one, creating a merge commit when histories diverge. Preserves the full branching topology.