Git Fetch Pull Push

Sync with remotes efficiently and fix divergent branches.

  • git push
  • force with lease
  • divergent branch
  • git fetch
  • pull rebase

Git Fetch Pull Push

Sync with remotes efficiently and fix divergent branches.

Commands

CommandWhat it does
git fetch originDownload all remote updates, change nothing locally
git pull --rebase --autostashRebase local work onto fetched updates
git push --force-with-leaseSafe force-push for rebased private branches
git status -sbAhead/behind counts vs upstream
git branch --set-upstream-to=origin/mainFix a branch with no tracking info

Example

git pull --rebase --autostash
git status -sb
git push --force-with-lease

FAQ

Divergent branches error on pull — now what?

Pick a strategy once: git pull --rebase for feature branches, git pull --ff-only when you expect no local commits.

force vs force-with-lease?

--force-with-lease refuses if someone else pushed first, preventing you from silently dropping their work.

Preguntas frecuentes

Divergent branches error on pull — now what?
Pick a strategy once: git pull --rebase for feature branches, git pull --ff-only when you expect no local commits.
force vs force-with-lease?
--force-with-lease refuses if someone else pushed first, preventing you from silently dropping their work.

Git