What is `git checkout --orphan` used for?
The core use for git checkout --orphan
is to create a branch in a git init
-like state on a non-new repository.
Without this ability, all of your git branches would have a common ancestor, your initial commit. This is a common case, but in no way the only one. For example, git allows you to track multiple independent projects as different branches in a single repository.
That's why your files are being reported as “changes to be committed”: in a git init
state, the first commit isn't created yet, so all files are new to git.
It's used by e.g. GitHub Pages, which stores a repo's website inside the repo but on a separate branch. There's no reason to store anything but the website's history on this branch.
We were moving to a public repo from a private one and because of sensitive commit information, we wanted to reset a branch as new
and push it as a blank branch. Here is a typical way of a workflow for that:
how to delete all commit history in github?