Pulling Changes
Fetch and merge changes from a remote repository with git pull.
What is Pull?
git pull is a combination of two commands:
git fetch- Download changesgit merge- Integrate changes
Basic Pull
Pull Commands
| Command | Description |
|---|---|
git pull | Pull from tracked remote |
git pull origin main | Pull specific remote/branch |
git pull --rebase | Pull and rebase |
git pull --no-commit | Pull without auto-commit |
Pull vs Fetch
| Command | Effect |
|---|---|
git fetch | Downloads changes, doesn't merge |
git pull | Downloads and merges |
Fetch is safer when you want to review changes first:
git fetch
git log origin/main
git merge origin/main
Pull with Rebase
Instead of creating a merge commit:
git pull --rebase
This replays your commits on top of the remote changes, creating a linear history.
Handling Pull Conflicts
When pull creates conflicts:
- Git stops and marks conflicts
- Edit files to resolve
- Stage resolved files:
git add . - Complete merge:
git commit
Or abort:
git merge --abort
Pull Strategies
Configure default strategy:
git config pull.rebase true
# or
git config pull.ff only
Best Practices
- Pull before pushing: Avoid rejected pushes
- Commit or stash first: Clean working directory
- Pull frequently: Smaller, easier merges
- Use rebase for cleaner history: When appropriate
Exercise: Pull from Remote
Pull the latest changes from origin:

