Git & Version Control · Cheatsheet
Git Branches and Remotes Cheatsheet
Create branches, inspect remote tracking, fetch updates, and use fast-forward merges. Check shared-branch rules before publishing changes.
39 commands 7 sections
No entry matches that filter.
-
Check the project rulesSome shared projects require all work on one branch -
Commit or preserve your workStart a merge with a clean working tree -
main, feature, originExample names; replace them with your project names -
Remote-tracking branchA local record of remote state, refreshed by fetch -
Fast-forward onlyUpdate a branch only when its tip can move forward
-
git branch --show-currentPrint the current branch name; detached HEAD gives no name -
git branch --listList local branches -
git branch --remotesList local remote-tracking references -
git branch --allList local and remote-tracking branches -
git branch -vvShow branch tips and configured upstreams -
git status --short --branchShow working state and available ahead or behind counts
-
git branch featureCreate feature at the current commit without switching -
git switch featureSwitch to an existing local branch -
git switch -c featureCreate a branch at HEAD and switch to it -
git switch -c feature origin/mainStart a new branch from the fetched remote reference -
git switch --track origin/featureCreate a local branch that tracks origin/feature
-
git remote -vShow configured remote names and URLs -
git remote get-url originRead the fetch URL for origin -
git remote show -n originShow cached remote details without contacting the server -
git fetch originFetch remote objects and update remote-tracking references -
git fetch --allFetch all configured remotes that permit this operation
-
git log HEAD..origin/main --onelineList fetched main commits absent from HEAD -
git log origin/main..HEAD --onelineList local commits absent from fetched main -
git diff --stat HEAD origin/main --Compare local and fetched file snapshots -
git diff --name-only --diff-filter=UList paths that still have merge conflicts -
git merge-base HEAD origin/mainFind a common ancestor when one exists
-
git merge --ff-only origin/mainFast-forward the current branch or refuse divergence -
git pull --ff-onlyFetch the upstream and require a fast-forward update -
git merge featureMerge feature into the current branch; conflicts can stop it -
git add -- <resolved-file>Stage a file after you resolve and review its conflicts -
git merge --continueFinish an active merge after all conflicts are resolved -
git push --dry-run origin featurePreview the remote update without sending it -
git push -u origin featurePublish feature and set its upstream if the push succeeds
Related cheatsheets
Tools for this work
- Env MergeMerge a base .env with an overlay using a conflict rule you pick, and download one .env file.
- Merge ICSCombine several .ics calendar exports into one calendar file, with optional UID dedupe.
- Merge BookmarksCombine two or more bookmarks.html exports from Chrome, Firefox, Edge or Safari into one file to import.