Some git commands I’d somehow never needed — until recently.
Worktrees
Back when development was slow, the workflow was simple: one directory, work, commit, push, open a PR. Even revert/rebase/merge counted as advanced. But once AI started accelerating everything, features started arriving in parallel — and sometimes you genuinely need to develop two things at once, in different branches. Sketching it into two cloned directories quickly falls apart (npm install twice? .env confusion? node_modules of the century?). That’s when git’s shadow-clone jutsu enters the scene: worktree.
A worktree is a second (or third…) checkout directory that shares the same .git. It supports multiple working directories, each checked out to a different branch. It doesn’t copy the repository, so worktrees nesting inside other repos’ paths basically doesn’t affect each other. The directory holding .git itself is the main worktree; a worktree cannot check out the same branch twice (well, it produces no other trouble). Normally available naturally, no extra installs. Two machine-level tunables are worth knowing: worktree.guessRemote and worktree.guessRemotePath. Note that .env and other files not tracked by branches are not carried over to new worktrees — manage those yourself. If you delete the main worktree directory, the worktrees still contain files like .env — as for whether that means something has gone wrong, I suggest asking your LLM of choice; it’s better at it than I am.
Common commands:
Create a fresh worktree:
git worktree add <target-dir> [branch]
List all worktrees:
git worktree list
Remove a worktree:
git worktree remove <absolute-path>
Little things you’d rather not share? There’s more than .gitignore
We’ve known about .gitignore since we learned to walk. But sometimes it’s not enough. Consider these cases:
Ignoring a file that’s already tracked
One uncomfortable truth first: .gitignore only stops untracked files. For something already in history, adding it to .gitignore gets you nothing — it has tenure now; you can’t just fire it.
You can’t execute it directly, so first “retire” it, then blacklist it: remove it from the index but keep the local file (--cached is the lifeline):
git rm --cached <file>
After committing, it’s free; now .gitignore will actually catch it.
Ignoring something without touching .gitignore
Sometimes you just want to quietly ignore a few things on your own machine — local temp files, your personal editor config — and it feels rude to pollute the team’s .gitignore with your private grudges. Git leaves a backdoor for exactly this:
.git/info/exclude
Same syntax as .gitignore, but the rules only apply locally and are never committed. A .gitignore that belongs to you alone — quiet, stealthy, teammates unaffected. An introvert’s dream.
Nonsense begins (skip to the end)
Oh right. (This part is mostly rambling; read with supervision or skip at will.) I once wanted to modify .git/info/exclude… inside a submodule. Nesting, or “submodule” in polite company. So I happily open up that .git and — it won’t see me. It’s not a directory at all. It’s a file, containing exactly one line:
gitdir: ../../.git/modules/my-submodule
A perfectly ordinary path, yet it reads like a note with someone else’s address on it. Fine — all I wanted was to edit one file, and now I’m on an address-hunting expedition. Seatbelts on, everyone; the blog’s annual literary segment officially begins:
Behind the Door
That year he was given a task: go update the register of a city. The map marked it clearly — right beside the city wall, under the doorplate
.git.But when he arrived he found no door there at all. Just a thin signboard, copied over with an address from somewhere far away.
So a missing-person search became an address search. Following the map, he passed through one directory layer after another, peeling an onion whose core might not exist, whispering at every door he pushed open: this time it has to be the real thing, right?
Finally, behind the last door there was no note — only a quiet underground city:
objects, a vast content-addressed warehouse where any given memory is stored exactly once in all the universe;refs, a row of signposts pointing down different timelines;logs, holding the city’s entire surveillance tapes. And the register itself,info/exclude, lay open on a small table in the corner, with a line written inside the cover:“This register is in effect locally only, and shall never be shared.”
On his way out, having made his edit, he couldn’t help asking the gatekeeper: why is the city’s real address written on a piece of paper?
The gatekeeper said: child, the city is alive. The day it moves, all it needs is a new slip of paper.
—And there’s the literature. Audience, exit in an orderly fashion. Now for the summary, in human words: in a submodule, .git is not a directory but a file, and one gitdir: line records where the real thing lives — my register had been sitting comfortably under the main repo’s .git/modules all along. Wrestling with this maze of “nothing behind the door but a note” is a waste of a life; better to just let Git lead the way:
cd $(git rev-parse --git-dir)
rev-parse --git-dir computes the real location of the current repo’s .git on the spot. Whether you’re slacking in the fifth level of subdirectories, toiling inside a worktree clone, or lost in submodule nesting to the point of existential doubt, this command drops you at the gate of the city you actually need — no more mystical puzzle-solving against relative paths.
Nonsense ends
And if you don’t even want that file to exist — it never gets committed, sure, but it sits in .git in plain sight for anyone who looks — there’s a sneakier move: skip config files entirely and go straight at the index:
git update-index --skip-worktree <file>
This slaps a “my local version is the truth” seal on the file: no matter how you modify it locally, status and diff will pretend nothing happened. Caveat: if the remote genuinely updates that file, pull will refuse — at which point remove the flag with --no-skip-worktree and let it back in.
One notch sneakier than skip-worktree is its sibling, --assume-unchanged:
git update-index --assume-unchanged <file>
Instant effect: you can do anything to the file and Git turns a blind eye throughout. But this flag was designed as a performance optimization — “don’t bother checking this huge file” — so its promise is flimsy: branch switches, rebases, and similar operations can silently clear it. One day you’ll discover “I definitely changed this file, why is nothing happening”, and congratulations, you’ve unlocked a several-hour ghost-hunting session.
A handy investigation trick for when you suspect files are playing dead:
git ls-files -v | grep '^[a-z]'
Everything listed is wearing a costume. Remember to fish each one back out with --no-skip-worktree or --no-assume-unchanged when done — don’t leave them living in a parallel timeline forever.
Whoever invented this thing deserves a cherry… pick
Back to the opening story: working in parallel, the other branch happens to hold exactly one commit that your current branch badly needs. merge hauls over the whole banquet table; rebase makes too much noise. You only want that one cherry. cherry-pick is the buffet tongs: sorry, I’m just taking this one piece.
What it does is blunt: it “copies” the specified commit onto your current branch and produces a brand-new commit. Copy, not relocation — the cherry on the original branch stays perfectly intact.
Pick one and taste it:
git cherry-pick <commit-hash>
Want the content but not a new commit record (apply it and stop at the staging area):
git cherry-pick -n <commit-hash>
A whole handful at once (A^..B means the inclusive range from A to B):
git cherry-pick <hash1> <hash2> <hash3>
git cherry-pick A^..B
Of course, cherries don’t grow on trees — conflicts will come when they come. Once resolved:
git cherry-pick --continue # sorted; move on to the next one
git cherry-pick --abort # bail out, nothing happened here
Hence “evergreen with use”: I once assumed I’d never touch these commands in my life, and now I open my mouth every day with “this one’s ripe — mind if I pick it first?”