Around Go: command line · 3 MIN READ
Git collaboration: fetch, compare, stash and push
Inspect upstream changes before integration and keep unfinished work recoverable.
A remote-tracking branch is your local record of a remote branch at the last fetch. Fetching updates that record without integrating it into your current branch. The examples assume an origin remote, a main branch and an existing topic branch you own.
Fetch and compare before merging
remote -v shows fetch and push destinations; inspect those before publishing. fetch origin updates remote-tracking references. The three-dot diff compares the topic branch against its merge base with origin/main, highlighting the branch contribution.
git remote -v
git fetch origin
git log --oneline HEAD..origin/main
git diff origin/main...HEADHEAD..origin/main lists commits reachable from origin/main but not HEAD. Fetch does not change your working files. A remote URL may contain sensitive information; avoid pasting it indiscriminately into public logs.
Temporarily store an unfinished tracked change
stash push -u includes untracked files as well as tracked edits, but not ignored files by default. apply restores a stash while retaining its saved entry. Inspect and resolve any conflicts before deciding to drop the saved copy.
git stash push -u -m "WIP before syncing"
git stash list
git stash show --stat "stash@{0}"
git stash apply "stash@{0}"
git status --shortOnly apply when a stash entry actually exists. apply can conflict; it does not mean every file was restored cleanly. The retained stash is useful until the restored work is checked. A stash is local, not a shared backup.
Integrate deliberately and publish the branch
On a clean main branch, pull --ff-only refuses an implicit merge when histories diverge. A topic branch push sets its upstream without rewriting remote history. A rejected push is evidence to fetch and inspect, not a reason to force-push blindly.
git switch main
git pull --ff-only origin main
git switch feature/health-check
git push -u origin feature/health-checkResolve or save local changes before switching branches. The pull updates main only if fast-forward is possible. Pushing the topic branch publishes commits; it does not merge them into main or submit an application release.
TAKE THIS WITH YOU
Fetch and compare before integrating. Preserve unfinished work, inspect conflicts and push the intended branch. Fast-forward refusal is a useful signal that history needs a deliberate decision.
Check your understanding
What does git fetch origin normally update?
Go to the source
Progress stays in this browser. No account needed.