All sheets / CI/CD & Release
Git
Commands for daily work and the release/debugging tasks interviewers ask about.
Everyday
git switch -c feat/x # new branch
git add -p # stage hunks interactively
git commit -m "feat: add x"
git commit --amend --no-edit # add to last commit (not pushed)
git push -u origin feat/x
git pull --rebase
git stash push -m wip; git stash popInspect
git log --oneline --graph --decorate --all
git log -p -- path/file # history of a file
git log -S "funcName" # commits that added/removed a string
git blame -L 10,20 file
git diff main...feat/x # changes on branch since it diverged
git show HEAD~1
git reflog # find "lost" commitsMerge vs rebase
| merge | rebase | |
|---|---|---|
| History | preserves, adds merge commit | linear, rewrites commits |
| Safe on shared branches | yes | no (never rebase public history) |
| Use | integrate PRs | update feature branch on main |
git merge --squash / "Squash and merge" collapses a branch into one commit.
Undo
| Goal | Command |
|---|---|
| Unstage | git restore --staged file |
| Discard local edits | git restore file |
| Undo last commit, keep changes | git reset --soft HEAD~1 |
| Drop last commit entirely | git reset --hard HEAD~1 |
| Undo a pushed commit safely | git revert <sha> |
| Recover after bad reset | git reflog then git reset --hard <sha> |
Release tasks
git tag -a v1.4.0 -m "v1.4.0"; git push origin v1.4.0
git cherry-pick <sha> # hotfix onto release branch
git switch -c release/1.4 v1.4.0
git describe --tags # nearest tag
git log v1.3.0..v1.4.0 --oneline # changelog rangeFind a regression
git bisect start
git bisect bad # current is broken
git bisect good v1.3.0 # last known good
# test, then mark: git bisect good | bad
git bisect run npm test # automate
git bisect resetInteractive rebase
git rebase -i HEAD~5 # pick / reword / squash / fixup / drop / edit
git commit --fixup <sha>; git rebase -i --autosquash main
git push --force-with-lease # safer than --forceConcepts
- Commit = snapshot + parent pointer(s); branch = movable pointer;
HEAD= current pointer. - Objects: blob (file), tree (dir), commit, tag. Content-addressed by SHA.
- Detached HEAD: checked out a commit, not a branch; create a branch to keep work.
fetchdownloads;pull= fetch + merge (or rebase).