Orphan branches in Git are rare as hens’ teeth though I’m writing from my personal experience. What, how and why are created orphaned branches will be the topics for today.
Orphan branch is a Git branch that has no parents (you don’t say) or git history if you will. Starts with a completely different / new root commit.
Although the proper way to create an orphaned branch is:
git switch --orphan <orphaned_branch_name>
It will delete ALL files from the working directory except the ones ignored by
Another less risky way with all files intact:
git checkout --orphan <orphaned_branch_name>
To commit and push this branch as empty run:
git commit --allow-empty -m "init commit orphan" git push origin <orphaned_branch_name>
- Deleting your Git repo commit history for various reasons including exposing sensitive data.
- Combining multiple repositories as one.
- Separate static website documentation from the actual source code.