Machine Room · 26 Nov 2026 · 11:11
Git Terms That Confuse Every Developer: Detached HEAD, Worktree, Reflog and More

Watch on YouTube
Git's eight most confusing terms are merge, rebase, stash, worktree, detached HEAD, reset, revert and reflog, and almost every one of them is a pointer moving between commits. This episode builds a few features on one small repo, with a teammate called Sam, and each term shows up at the moment we need it.
A branch like main is a pointer to one commit, and HEAD points at the branch we're on. git merge joins two branches with a merge commit. git rebase replays our commits on top of main as new commits with new IDs, which is why the golden rule says to merge, not rebase, once anyone else has the branch. git stash puts half-done changes aside so git switch can change branches. git worktree add gives an AI coding agent its own folder and branch in the same repository. git checkout on an old commit puts us in detached HEAD state, and git branch with a name and the commit's ID keeps a commit made there. git reset with --soft, no option (--mixed) or --hard moves a branch back before we push; git revert undoes a pushed commit with a new commit. And git reflog finds the commit a git reset --hard lost.
This episode with chapters, full transcript and sources: https://themachineroom.dev/v/git-confusing-terms/?utm_source=youtube&utm_medium=description&utm_campaign=git-confusing-terms
Chapters
- 0:00The 8 Terms: one repo, one teammate
- 0:25The Picture: commits, branches and HEAD
- 1:36Merge: git merge and the merge commit
- 2:44Rebase: replayed commits and the golden rule
- 4:47Stash: putting half-done work aside
- 5:38Worktree: a second folder for an AI agent
- 6:55Detached HEAD: a commit with no branch
- 8:09Reset: soft, no option and hard
- 9:05Revert: undoing a pushed commit
- 10:03Reflog: finding a lost commit
Notes
the booking app, Sam and every commit ID on screen come from a real run of git 2.50.1 on a made-up repo. "Reset for commits we haven't pushed, revert for pushed ones" is our step from Pro Git's rule that pushed work should be treated as final. The Git logo is by Jason Long, CC BY 3.0 (https://creativecommons.org/licenses/by/3.0/).
Sources
- Pro Git, 2nd edition, Scott Chacon and Ben Straub (CC BY-NC-SA 3.0) — https://git-scm.com/book/en/v2
- git-worktree manual — https://git-scm.com/docs/git-worktree
- git-revert manual — https://git-scm.com/docs/git-revert
- git-reflog manual — https://git-scm.com/docs/git-reflog
- Worktrunk README (git worktrees for parallel AI agents) — https://github.com/max-sixty/worktrunk
Transcript
The narration, word for word, from the subtitle file that ships with the video.
0:00The 8 Terms: one repo, one teammate
Git has eight terms that confuse almost everyone at first, like rebase, detached HEAD and reflog. In this video, we build a few features on one small repo, and each term shows up at the moment we need it. Almost every one of them is a pointer moving between commits. So before the eight terms, we need that picture.
0:25The Picture: commits, branches and HEAD
Right now, our repo is three commits: a search page, a booking page and a payment page. Each commit points back at the one before it. Main isn't a folder, and it isn't a copy of our code. It's a branch, and a branch is just a pointer to one commit. Right now it points at the payment page. Every time we commit, Git moves main forward to the new commit. We want to build a login page, so we make a branch called login. That adds a second pointer on the same commit, and nothing is copied. Git also has to know which branch we're working on currently. It keeps one more pointer for that, called HEAD, and HEAD points at our current branch. Making the login branch didn't move it, so we switch to login, and now HEAD points at login. We commit twice, a login form and then email validation. Login moves forward with each commit, because that's where HEAD is, and main stays where it was. Now we have to get those two commits into main.
1:36Merge: git merge and the merge commit
The first term is merge, and it's how our login commits get into main. While we built the login page, our teammate Sam pushed a bug fix. So first we switch to main and pull, and Sam's fix comes down onto our main. Now the history has split in two. Login has our commits, main has Sam's fix, and the last commit they share is the payment page. We run git merge login. Git takes the newest commit on each side and the one they share, and combines them. Sam changed a different file, so Git does it without asking us anything. Git saves the result as a new commit, called a merge commit, and main moves forward to it. Our commits and Sam's fix are now all there, in this new merge commit, and the graph shows where the history split and where it joined. Every merge like this leaves that split in the history. Rebase is the other way to join two branches, and it leaves one straight line.
2:44Rebase: replayed commits and the golden rule
The second term is rebase. We start the same way. We make a branch called filters, commit twice for the search filters, and Sam pushes another fix to main while we work. We pull main, and the history has split again, with our commits on one side and the new fix on the other. This time we stay on filters and run git rebase main. Git lifts our two commits off, moves filters to the top of main, and replays them there one at a time, after Sam's fix. The code ends up the same as a merge would give us. But there's no merge commit and no split. The history reads as if we started after Sam's fix. The cost is that the replayed commits are new commits, with new IDs. Our old two are gone from the branch. And that can make things confusing very fast. Say Sam had pulled our filters branch before the rebase, and added one commit on top of our sort by price commit. That's a problem, because Sam's commit still points at the old sort by price commit, the one that's gone from our branch. When we push filters again and Sam pulls, Git sees two histories of the same work: our two new commits, and Sam's commit sitting on our two old ones. The IDs don't match, so Git can't tell they're the same changes. It merges them, and our work shows up twice in the history. So, the golden rule of rebasing. Before we rebase, we ask one question: does anyone else have this branch? If yes, we merge. We rebase while the branch is only ours, and once others have it, we merge. Next we start on the refunds branch. We're halfway through a change when Sam needs us on main right now.
4:47Stash: putting half-done work aside
The third term is stash. We're on a branch called refunds, with a change to the payment page that's only half done, and we have to switch to main to fix a bug. We try the switch, and Git refuses, because it would overwrite our half-done change. We could commit it first, but we don't want a commit of half-done work. So we run git stash. Git puts our uncommitted changes aside and takes the files back to the last commit. Now the switch works. We go to main, fix the bug, commit, push, and come back to the refunds branch. Then we run git stash pop, and our half-done change is back in the files, the way we left it.
5:38Worktree: a second folder for an AI agent
The fourth term is worktree. We're still building on the refunds branch, and we want an AI coding agent to build the refund emails at the same time. If the agent worked in our folder, its edits would land right next to our half-done ones. Git status would show them all together, and one commit would take both. So we run git worktree add, with a new folder and a new branch. Git makes a second folder next to ours, with that branch checked out in it. Each folder has its own files and its own HEAD. Our HEAD still points at the refunds branch, and the HEAD in the new folder points at the refund-emails branch. The agent works in its folder and commits there. We keep working in ours and commit here. Each branch moves forward in its own folder, at the same time. It isn't a second copy of the repo. Both folders share the same commits, so we can see the agent's commit from our folder. When the agent is done, we merge its branch like any other, and remove the folder with git worktree remove. The branch and its commits stay.
6:55Detached HEAD: a commit with no branch
The fifth term is detached HEAD. A bug showed up on the search page, and we want to see the app as it was a few commits ago. So we check out that old commit by its ID. Git prints a long message saying we're in detached HEAD state. Until now, HEAD always pointed at a branch. Now it points straight at a commit, with no branch in between. Looking around here is safe. We can read the old code and run it, and no branch changes. The catch comes if we commit here. Normally a new commit moves our current branch forward. But here we're in the middle of the history, and HEAD points at this old commit, not at main. So main doesn't move forward. The new commit sits on top of the old one, and no branch points at it. When we switch back to main, Git warns us that we're leaving one commit behind, not connected to any branch. And the warning gives us the fix: git branch, a name, and that commit's ID. Now a branch points at the commit, so it's kept like any other.
8:09Reset: soft, no option and hard
The sixth term is reset. We commit a new banner on the search page, and right away we see it's broken. We haven't pushed it yet. Reset moves our current branch back to an older commit. We tell it to go back a single commit, and main points at the commit before the banner again. So the banner commit is off main. What happens to the banner changes themselves depends on one option. With soft, the changes stay exactly as they were, ready to commit again. With no option, the changes stay in our files, but we have to git add them again. With hard, the changes are removed from our files too. And anything else in our files that we hadn't committed is gone for good. We only want to fix the banner, so we use soft, fix it, and commit again.
9:05Revert: undoing a pushed commit
The seventh term is revert. We pushed the banner, and Sam has already pulled it. Then we find a bug in it, and it has to come out. We can't use reset this time. Sam already has the banner commit, and the golden rule from rebase applies here too: we don't change commits other people have. So we run git revert on the banner commit. Git makes a new commit that does the opposite: every line the banner commit added, the new one takes out. The banner commit stays in the history, and the revert commit sits right after it. Nothing was taken away, so we push like normal, and Sam pulls like normal. So reset takes a commit off the branch, and it's for commits which we haven't pushed to main or origin. Revert adds a commit that undoes one, and it's for commits we've already pushed.
10:03Reflog: finding a lost commit
The eighth term is reflog. We make two more commits on main: a sale badge, which is good, and a price label, which is wrong. We want to drop the label, so we reset hard. But by mistake we go back two commits. Now the sale badge commit is gone too. Git log doesn't show it, and no branch points at it. But Git has been keeping a log of every place HEAD has pointed. That's the reflog. Every commit, every switch and every reset we made is a line in it. We run git reflog, and the sale badge commit is in the list, with its ID. We reset main to that ID, and the sale badge is back. The wrong label is gone, which is what we wanted in the first place. The reflog is only on our machine, and it only knows commits. Changes we never committed aren't in it. Those are the eight terms. And if this helped, subscribe.
← How Shopify Survives Black Friday: 489 Million Requests a MinuteWhat Is SSH? What Really Happens When You Log In to a Linux Server →