Skip to content

Instantly share code, notes, and snippets.

@seanbuscay
Created June 27, 2013 15:26
Show Gist options
  • Save seanbuscay/5877413 to your computer and use it in GitHub Desktop.
Save seanbuscay/5877413 to your computer and use it in GitHub Desktop.
Create an orphan branch in a repo.
cd repository
git checkout --orphan orphan_name
git rm -rf .
rm '.gitignore'
echo "#Title of Readme" > README.md
git add README.md
git commit -a -m "Initial Commit"
git push origin orphan_name
@mralusw
Copy link

mralusw commented Mar 30, 2024

Note that using git switch --orphan <branch name> automatically removes ALL files from the working tree.

Note that whatever is ignored by .gitignore won't be removed.

Note that git switch --orphan <branch name> automatically removes ALL tracked files from the working tree (as it should, since we don't want files from other branches — it's an orphan branch). It will not remove

  • untracked files
  • modified (not yet committed) tracked files (because it refuses to proceed in this scenario)

This is independent of .gitignore. However, there are many other ways to exclude files (e.g. .git/info/exclude, git update-index --skip-worktree etc). If you use any of those, possibly together and along .gitignore, you probably have bigger things to worry about.

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