

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


PRINT DOUBLE-SIDED • Replace example names/URLs with your own
git init -b main git clone https://github.com/user/repo.git git clone -b branch-name git clone --depth 1 # shallow clone
Stage Command Purpose Working → staging git add Select changes Staging → local git commit -m "msg" Save snapshot Local → remote git push Upload commits Remote → local/work git pull Fetch + merge Remote → local only git fetch Download, do not merge git status -sb # status, short git diff # unstaged changes git diff --staged # staged changes git log --oneline --graph --all git show # inspect commit git blame # line history
git add # specific file git add. # all current changes git add -p # choose hunks git restore --staged # unstage git commit -m "feat: add login" git commit -am "fix: typo" # tracked files only git commit --amend --no-edit
git branch # local list git branch -a # local + remote git switch -c feature/login # create + switch git switch main git branch -m new-name # rename git branch -d feature/login # safe delete git branch -D feature/login # force delete git push origin --delete feature/login
History Preserves branch graph Replays commits; linear history Merge commit Sometimes No extra merge commit Shared branch Usually safe Avoid rewriting shared history Use for Integrating work Cleaning local branch history git merge feature/login git merge --no-ff feature/login git merge --abort git rebase main git rebase -i HEAD~3 # reorder/squash/edit git rebase --continue git rebase --abort git cherry-pick
incoming-branch version >>>>>>> feature/login
git add git commit # finish merge git merge --abort # cancel instead git mergetool # visual tool
PRINT DOUBLE-SIDED • Replace example names/URLs with your own
git remote -v git remote add origin git remote set-url origin git remote show origin git push -u origin main # set upstream git push origin main git fetch origin git fetch --prune # remove stale refs git pull --rebase origin main git push --force-with-lease # caution
Goal Command Keeps work? Discard unstaged file git restore No local edits Unstage, keep edits git restore --staged Yes Undo commit, keep staged git reset --soft HEAD~1 Yes Undo commit, keep unstaged git reset HEAD~1 Yes Discard commit + edits git reset --hard HEAD~1 NO - destructive Undo shared commit git revert Creates new commit Find lost commit git reflog Recoverable refs Preview untracked cleanup git clean -n Dry run Delete untracked files git clean -fd Destructive
git stash push -m "WIP: form" git stash -u # include untracked git stash list git stash apply # keep stash git stash pop # apply + remove git stash show -p stash@{0} git tag -a v1.0.0 -m "Release" git push origin v1.0. git push --tags
git switch main && git pull origin main git switch -c feature/new-thing
git add. && git commit -m "feat: new thing" git push -u origin feature/new-thing
git remote add upstream git fetch upstream git switch main && git merge upstream/main git push origin main
gh auth login gh repo create my-project --public gh repo clone owner/repo gh pr create --title "Add login" --body "..." gh pr list gh pr checkout 42 gh pr status gh pr merge 42 --squash gh issue create --title "Bug" --body "..."
node_modules/ venv/ pycache/ .env .env.local .DS_Store *.log *.pyc build/ dist/ .vscode/
git rm --cached git check-ignore -v
Error / symptom Likely fix Not a git repository cd into repo or git init Push rejected / refs behind git pull --rebase, resolve, then push Merge conflict Edit markers → git add →git commit Detached HEAD git switch main or create a branch No upstream branch git push -u origin Permission denied (publickey) Configure SSH key or use HTTPS Uncommitted changes block switch git stash or commit first Unrelated histories Confirm repos; only then consider --allow- unrelated-histories
git config --global alias.st status git config --global alias.co checkout git config --global alias.br branch git config --global alias.lg "log --oneline --graph --all" git log -S "search-term" --oneline git bisect start # binary-search a bug git bisect good git bisect bad # repeat, then: git bisect reset
Task Command Start / copy git init • git clone Check state git status -sb Save a change git add. • git commit -m "msg" Share / update git push • git pull Branch git switch -c History graph git log --oneline --graph --all Undo safely git revert Temporarily park git stash / git stash pop