How to Create a New Empty Branch for a New Project

less than 1 minute read

Sometimes, you might need branches in your git repositories, which are off the track of the main repository timeline. You want to store specific files there, and none of the original files, stored across your master and other feature branches. Luckily, git comes with an option called orphan branch. An orphan branch is basically like a store on its own, with its own history. You can delete all the existing files inside an orphan branch, and this won’t affect their state across master and other branches at all.

You can create a branch as an orphan:

git checkout --orphan <branchname>

This will create a new branch with no parents. You can then clean the working directory with:

git rm --cached -r .

and add the new files you only want to have there.

Leave a comment