orphan

Git: creating clean branch

Sometimes you need to create a clean branch in git that has no history.
This is the case for example when you need to have two or more code bases, but you are have just a single repository. Sad but happens !
You have to do with what you have.

In this case use the following recipe :

#fetch the original repo.
#Normally you would like dir_name to be the same as the new branch name
git clone ssh://.... dir_name
cd dir_name
#create the orphan branch
git checkout --orphan blah
#cleanup all the files, you dont need them, right ? 
git rm -rf .
#add a file so you can commit
echo start > readme.txt
git commit -m 'creating an orphan branch ...' -a
#now the branch shows up
git branch
# ... no commit log, like we wanted
git log
# time to make the branch show up in the remote repo
git push -u origin blah