The Duck Kit
Each one with what it does and when to use it. Three minutes to read, saved for the bad day.
The sheet comes out of this very page: print it or save it as PDF.
Rescue
git reflogGit writes down every move of HEAD in a separate notebook. The commit you thought was dead is in there.
When: You deleted a branch without merging, or a reset took something with it.
Covered in piece 007
git switch -c rescate <hash>Branch off the commit you found in the reflog.
When: You have the hash and want it back without touching anything else.
Covered in piece 007
git reset --soft HEAD~1Undoes the last commit and keeps your changes staged, ready to redo it.
When: The commit is yours and nobody has pulled it.
Covered in piece 008
git revert <hash>Deletes nothing; writes a new commit that does the opposite.
When: Someone already pulled it. What others have is not rewritten.
Covered in piece 008
git reset --hard <hash>Rewinds the branch to that commit and throws away everything after it.
When: Only with the reflog open next to you. It rewinds the tape, it is not a recycle bin.
Not covered yet
git restore <archivo>Puts the file back the way the last commit left it.
When: You touched it by mistake and never committed. Careful, there is no reflog for this.
Not covered yet
git checkout <hash> -- archivoBrings back a single file as it was in that commit, without moving the branch.
When: One file broke and the rest of your work is fine.
Not covered yet
git merge --abortUndoes the half-finished merge and leaves you as you were before the conflict.
When: Twenty minutes in and you no longer know what you are looking at. Works for rebase too.
Not covered yet
git clean -ndLists the untracked files it would delete, and deletes none.
When: Always before -fd. That n is the difference between tidying up and crying.
Not covered yet
git stashHides your half-done work and leaves a clean tree.
When: A five-minute interruption. Remember to pop it.
Covered in piece 002
git bisect startBinary search over history. 400 commits resolve in 9 tests.
When: Something broke and you do not know when.
Covered in piece 011
Every day
git mergeJoins branches with a merge commit. Keeps history as it actually happened.
When: On main. It is the one that will not cause you trouble with anyone.
Covered in piece 001
git rebase mainReplays your commits on top of another branch. Clean line, new hashes.
When: On your branch and only yours, before opening the PR.
Covered in piece 001
git cherry-pick <hash>Brings a single commit over from another branch, without dragging ten others.
When: You need that one change and only that one. No copy-paste.
Not covered yet
git switch -Goes back to the branch you were on. It is Git's cd -.
When: You have spent all day bouncing between two branches.
Not covered yet
git diff --stagedShows exactly what is going into the commit, not one line more.
When: Right before committing. It is the last checkpoint before the door.
Not covered yet
git add -pShows you the diff hunk by hunk and makes you say yes or no to each one.
When: The agent wrote 300 lines and you have not read them.
Covered in piece 010
git push --force-with-leaseForce-pushes only if nobody has pushed since your last fetch.
When: Every time you push a rewritten branch. Never plain --force.
Not covered yet
git log --oneline --graph --allDraws the real shape of your history in the terminal, branches included.
When: Before rebasing, to see where each branch actually comes from.
Not covered yet
git blame -L 40,60 archivoTells you which commit wrote each line of that chunk.
When: Not to find someone to blame. To find the commit that explains why.
Not covered yet
git log -S "nombreDeLaFuncion"Finds the commits where that text appeared or disappeared.
When: The function was there, now it is gone, and nobody remembers taking it.
Not covered yet
git tag -a v1.0 -m "primera"Pins a fixed name on a commit, and the name travels with the repo.
When: Before deploying. Nobody remembers a hash; everybody remembers v1.0.
Not covered yet
git worktree add ../bug mainA separate folder on another branch, without touching the one you have open.
When: The urgent bug will take a while and you would rather not remember a stash.
Covered in piece 002
.gitconfig aliases
undo = reset --soft HEAD~1A .gitconfig alias. Undoes the commit and keeps your changes.
When: You will use it more than you think.
Covered in piece 012
amend = commit --amend --no-editFixes the last commit without opening the editor or rewriting the message.
When: You forgot a file. Again.
Covered in piece 012
wip = !git add -A && git commit -m wipSaves everything in one throwaway commit.
When: The meeting starts in thirty seconds.
Covered in piece 012
st = status -sbYour status in two lines instead of twenty.
When: A thousand times a day. It is the one you will use most.
Not covered yet
unstage = restore --stagedTakes the file out of the staging area without touching what you wrote.
When: You over-added with git add . and only want that undone.
Not covered yet
please = push --force-with-leaseForce-push without stepping on anyone, and with good manners.
When: After every rebase. If you have to say please, make it the safe one.
Not covered yet
Terminal
:wqSaves and quits vim. With that you are no longer trapped.
When: It is 3 a.m. and you came in over SSH.
Covered in piece 005
Ctrl + RSearches backwards through your history as you type bits of the command.
When: That endless command from three days ago you are not about to rebuild.
Not covered yet
sudo !!Repeats the previous command, this time with permissions.
When: Permission denied. Do not type the whole thing again.
Not covered yet
cd -Goes back to the previous folder. Same idea as git switch -.
When: You are hopping between two folders that live miles apart.
Not covered yet
lsof -i :3000Tells you which process is holding the port, with its PID.
When: address already in use, and you do not know what you are about to kill.
Not covered yet
chown $USER archivoChanges the file's owner, which is what was actually wrong.
When: You were about to run 777. That does not fix the permission, it fires the doorman.
Covered in piece 009
Craft
.editorconfigOne file at the root and nobody argues tabs versus spaces again.
When: Today. In every repo you have.
Covered in piece 003
git config --global core.excludesFile ~/.gitignoreOne ignore file of your own for every repo, without dirtying anyone else's.
When: The first time a teammate asks you to take the .DS_Store out.
Not covered yet
git config --global pull.rebase truegit pull stops inventing merge commits every time you catch up.
When: Today, on every machine you own. Your history will thank you.
Not covered yet
npm ciInstalls exactly what the lockfile says, wiping node_modules first.
When: In CI, and on the day of it works on my machine.
Covered in piece 004
.git-blame-ignore-revsThe list of commits blame should skip, like the big reformat.
When: The day you reformat the whole project and would rather not sign every line.
Not covered yet
The commands that get you out of trouble, on one sheet. Free.
Each one with what it does and when to use it. Three minutes to read, saved for the bad day.
One email with the kit. Nothing else. Unsubscribe whenever.
The Duck Kit · duvanh.dev