Sometimes you may need to create a brand new branch on a git project that doesn't contain anything present on the other branches nor shares an history with them, called orphan branch.
This snippet describes how to do it:
BRANCH_NAME=$1 git checkout --orphan $BRANCH_NAME git rm -rf . rm .gitignore echo "# $BRANCH_NAME" > README.md git add README.md git commit -m "Initial commit for branch $BRANCH_NAME" git push origin $BRANCH_NAME
This snippet can be used as a sequence of commands, replacing
$1 with any value for the branch name, or in a bash script, for example naming it orphan_branch.sh and running it with
sh ./orphan_branch.sh new_branch_name.
More information can be found in the git reference guide at the git checkout documentation.