Skip to content

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

git fetch origin

Fetch updates remote-tracking branches such as origin/main. Inspect them before deciding how to integrate the changes:

git log --oneline main..origin/main

Pull and integrate

git pull --ff-only origin main

--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:

git fetch origin
git merge origin/main

Push local commits

git push origin main

Set tracking when publishing a new branch:

git push --set-upstream origin feature/<short-description>

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.