Git

Lesson 05

Fetch, pull, and rebase sync

Fetch before integrating upstream work, then choose merge or rebase intentionally for the branch you are on.

Good Code

sync-feature.sh
# Fetch makes upstream changes visible before integration.
git fetch origin
git log --oneline --decorate --max-count=5 HEAD..origin/main
git rebase origin/main
npm test

Bad Code

sync-feature.sh
# Pulling without inspecting upstream makes the integration implicit.
git pull
git push --force
git status

Review Notes

What to review

Good Code

The good version fetches first, inspects upstream commits, rebases the feature branch intentionally, and runs tests after integration.

Bad Code

The bad version lets pull decide the integration behavior and follows with a force push without checking what changed.

Takeaways

  • Sync commands should show what changed upstream before they rewrite or merge local history.