Skip to content

Instantly share code, notes, and snippets.

@atifaziz
Last active September 7, 2021 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atifaziz/59912c18c82d1b06cc24a427ec88aa8f to your computer and use it in GitHub Desktop.
Save atifaziz/59912c18c82d1b06cc24a427ec88aa8f to your computer and use it in GitHub Desktop.
Create an orphan branch without checking it out
git stash # 1. save index changes
git rm -r --cached . # 2. empty the index
git branch orphan ( # 5. create the orphan branch
git commit-tree -m 'Empty commit' ( # 4. commit the empty tree
git write-tree)) # 3. write the empty index
git reset HEAD # 6. revert emptying of the index
git stash pop --index # 7. restore stashed changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment