Some branches have nothing to do with the code, like a gh-pages branch with a built website or a branch for documentation. They don’t need the project’s history at all.
git switch --orphan gh-pages
Git creates the branch with no parent commit and empties your working tree of tracked files. The first commit you make on it becomes a new root, completely separate from main. Add the files you want, commit, and push like any branch:
echo "Hello" > index.html
git add index.html
git commit -m "First page"
git push -u origin gh-pages
I like that the branch stays small. A website build doesn’t need years of source history, and cloning only that branch with --single-branch is quick.
Don’t panic when your files disappear after the switch. They’re still safe on the branch you came from, and git switch main brings them back. Untracked and ignored files stay where they are, so check git status before you run git add . on the new branch, or you’ll commit your build folder or node_modules by accident.
Because the branch shares no history, merging it into main later gives an error about unrelated histories. That’s intended, and it’s a sign you probably didn’t want to merge it anyway.
Further reading: git-switch documentation
Going deeper: Moving on from hdtv: how to export your TV show list to Trakt.tv