Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Git: Creating an empty branch
git stash # Stash changes if any
git symbolic-ref HEAD refs/heads/${NEW_BRANCH} # Change head to a new, non-existing ref
git rm -rf . # Delete files from version control and working directory
rm -r . # Delete files from file system
git commit --allow-empty -m "Created new branch ${NEW_BRANCH}" # Commit changes in the new branch
@ks-arunkumar

This comment has been minimized.

Copy link

@ks-arunkumar ks-arunkumar commented Aug 18, 2016

i tried this git checkout --orphan new. It returned switched new branch 'new' but when i do git branch -a my new branch is not there.
any suggestions...

@shubsaini09

This comment has been minimized.

Copy link

@shubsaini09 shubsaini09 commented Mar 8, 2017

git checkout --orphan new will create a new branch with zero commits on it, however all of your files will be staged. At that point you could just remove them. Then create a dummy file, write something and push it to origin. Then a history will be created for your branch and you will be able to see your new branch when you do git branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment