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
| Command | What it does |
|---|---|
git fetch origin | Download all remote updates, change nothing locally |
git pull --rebase --autostash | Rebase local work onto fetched updates |
git push --force-with-lease | Safe force-push for rebased private branches |
git status -sb | Ahead/behind counts vs upstream |
git branch --set-upstream-to=origin/main | Fix 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.
常見問題
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
Git Config Essentials
Set identity, defaults, and aliases for Git on a new machine.
Git Clone and Init
Start a repo from scratch or copy a remote repository locally.
Git Add and Commit
Stage changes and record them as commits with clear messages.
Git Branch Basics
Create, list, rename, and delete branches for parallel work.