git pull
Fetch remote changes and merge them into your current branch
Practical Example
git pull origin main # fetch + merge git pull --rebase origin main # fetch + rebase (linear history) git config --global pull.rebase true # make rebase the default
Command Overview & How It Works
Combines two operations: git fetch (downloads remote data) followed by git merge (integrates it into your current branch). This is the primary command for keeping your local branch up to date with the remote. Use git pull --rebase instead of a regular pull to rebase your local commits on top of the fetched changes — this creates a linear history instead of a merge commit. Use git pull --ff-only to fail if a fast-forward merge is not possible, which is a safe way to avoid accidental merge commits. Configure the default pull behavior with git config --global pull.rebase true (to always rebase). Before pulling, ensure your working directory is clean — use git stash or commit any in-progress work first.
Practical Tips
- •Run git pull --rebase to keep history linear instead of creating a merge commit on every pull.
- •Make rebase your default pull behavior with git config --global pull.rebase true.
- •Use --ff-only to fail instead of merging when a fast-forward is not possible — a safe guard against surprise merges.