Can I orphan an existing branch?

I’ve created a few branches in a repo, and realized too late (after making various changes to them) that I should have made them orphans. Is it possible to orphan them after the fact?

  • git merge: Removing files I want to keep!
  • Changing branches in git results in changed files
  • How can I review or secure remote branch deletions?
  • Bitwise operators, not vs xor use in branching
  • Publish only certain git branches
  • git: How to create a branch of my current work, but stay on my original branch
  • How to revert uncommited changes to a files of certain type in git
  • Git push to live server through limited ssh
  • Git revert last commit in heroku
  • What is the convention for the content of an initial/first git commit?
  • Git repository name does not update
  • Corrupted images in git repository
  • One Solution collect form web for “Can I orphan an existing branch?”

    I’m sure it’s possible. There might be a more efficient way, but this seems like it would work:

    1. Find the first commit in your old branch, and call it FIRST.
    2. git checkout --orphan new-branch $FIRST
    3. git checkout old-branch
    4. git rebase --onto new-branch $FIRST

    Now you have the original branch at old-branch and a new, orphaned branch at new-branch. You can, if you like, either delete or rename old-branch, and rename new-branch to old-branch.

    Git Baby is a git and github fan, let's start git clone.