Skip to content

Instantly share code, notes, and snippets.

@koraktor
Created March 26, 2009 08:04
  • Star 14 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save koraktor/85964 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

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