When working with Git worktrees, I sometimes want to create a brand-new branch that starts from scratch—completely clean with no commit history. This can be tricky, so here is a clear step-by-step guide that works well for me.
🛠️ Step-by-Step Guide
1. Create a Temporary Worktree
Use the git worktree
command to add a new worktree based on a temporary branch.
git worktree add ../skeleton -b temp-skeleton
💡 Run this from the root directory of your main repository. This creates the ../skeleton folder and checks out a new branch (temp-skeleton) there.
2. Navigate into the new worktree directory.
cd ../skeleton
3. Create an orphan branch
Now, create a new orphan branch, this branch will have no history at all.
git checkout --orphan skeleton
This command switches to a new branch named skeleton
with no previous commits. The files from temp-skeleton
will still be present, but they’re untracked on the new branch.
4. Clean the working directory
Remove all existing files that were carried over. Be careful to run these commands in the new worktree directory:
git rm -rf . # Removes tracked files
git clean -fdx # Remove any untracked files and directories
⚠️ Double-check you’re in the ../skeleton folder before running these commands!
5. Create the first commit
Create the first commit on the orphaned branch:
git commit --allow-empty -m "Initial commit on empty skeleton branch"
You can also add initial files (like a README.md
) before committing, and skip the --allow-empty
flag if you prefer.
6. Delete the temporary branch
Head back to your main repository and remove the temporary branch you no longer need:
cd /path/to/your/main/repo
git branch -D temp-skeleton
✅ You’re Done!
You now have a skeleton branch in its own worktree, starting from a completely clean slate, independent of your main branch history. This is a great setup for boilerplates, templates, or minimal example projects.