Files
mintlify__docs/git/pull.mdx
2026-02-09 20:46:44 +00:00

219 lines
3.4 KiB
Plaintext

---
title: git pull
description: Fetch from and integrate with another repository or local branch
---
Download and merge changes from a remote repository.
## Syntax
```bash
git pull [options] [<repository>] [<refspec>]
```
## Description
`git pull` fetches changes from a remote repository and immediately merges them into your current branch. It's essentially a combination of `git fetch` followed by `git merge`.
## Common usage
Pull from the default remote:
```bash
git pull
```
Pull from a specific remote and branch:
```bash
git pull origin main
```
## Options
<ParamField path="--rebase" type="flag">
Rebase instead of merge after fetching
```bash
git pull --rebase
```
</ParamField>
<ParamField path="--no-rebase" type="flag">
Force merge even if rebase is configured as default
</ParamField>
<ParamField path="--ff-only" type="flag">
Only update if fast-forward is possible
```bash
git pull --ff-only
```
</ParamField>
<ParamField path="--no-commit" type="flag">
Fetch and merge but don't create a merge commit automatically
</ParamField>
<ParamField path="--all" type="flag">
Fetch from all remotes
</ParamField>
## Examples
### Basic pull
```bash
git pull
```
### Pull with rebase
```bash
git pull --rebase
```
This applies your local commits on top of the remote changes, creating a cleaner history.
### Pull a specific branch
```bash
git pull origin feature-branch
```
### Pull from different remote
```bash
git pull upstream main
```
## Pull vs Fetch
`git pull` combines two operations:
```bash
# git pull is equivalent to:
git fetch
git merge origin/main
# git pull --rebase is equivalent to:
git fetch
git rebase origin/main
```
Use `git fetch` when you want to review changes before merging.
## Handling merge conflicts
If conflicts occur during pull:
```bash
git pull
# Conflicts detected
# Fix conflicts in your editor
git add resolved-file.txt
git commit -m "Resolve merge conflicts"
```
Or abort the merge:
```bash
git merge --abort
```
## Common workflows
### Start of day workflow
```bash
git checkout main
git pull
git checkout -b new-feature
```
### Before pushing your work
```bash
git pull --rebase
git push
```
### Update feature branch with main
```bash
git checkout feature-branch
git pull origin main
```
## Best practices
### Pull before push
Always pull the latest changes before pushing:
```bash
git pull
# Review any changes
git push
```
### Use rebase for cleaner history
```bash
git pull --rebase
```
This keeps your commits on top of the latest changes, avoiding unnecessary merge commits.
### Set rebase as default
```bash
git config pull.rebase true
```
### Pull frequently
Pull changes regularly to:
- Stay up to date with team changes
- Reduce merge conflicts
- Catch integration issues early
## Troubleshooting
### Uncommitted changes blocking pull
Stash your changes first:
```bash
git stash
git pull
git stash pop
```
### Diverged branches
If your branch has diverged:
```bash
git pull --rebase
# or
git pull --no-rebase
```
### Authentication issues
Update remote URL:
```bash
git remote set-url origin https://github.com/username/repo.git
```
## Related commands
- [git fetch](/git/fetch) - Download without merging
- [git merge](/git/merge) - Combine branches
- [git rebase](/git/rebase) - Reapply commits
- [git push](/git/push) - Upload changes
- [git stash](/git/stash) - Save temporary changes