Fetch, pull, and push changes
The three commands have different effects:
| Command | Downloads commits | Changes your current files | Uploads commits |
|---|---|---|---|
git fetch |
Yes | No | No |
git pull |
Yes | Usually yes | No |
git push |
No | No | Yes |
Fetch without integrating
Fetch updates remote-tracking branches such as origin/main. Inspect them before deciding how to integrate the changes:
Pull and integrate
--ff-only allows only a fast-forward update. If local and remote history diverged, Git stops instead of creating an unexpected merge commit.
When you need to choose the integration method explicitly:
Push local commits
Set tracking when publishing a new branch:
The short -u option means --set-upstream. After tracking is configured, git push and git pull can often omit the remote and branch names.
Do not push blindly
Check git status --short --branch and git log --oneline --decorate -n 5 before pushing, especially after a rebase or remote update.