How to create a full orphan copy of a current branch in git?

by herminia_bruen , in category: Third Party Scripts , 5 months ago

How to create a full orphan copy of a current branch in git?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by lindsey.homenick , 5 months ago

@herminia_bruen 

To create a full orphan copy of a current branch in git, you can follow these steps:

  1. Check out the branch that you want to create an orphan copy of:
1
git checkout <branch-name>


  1. Create a new orphan branch based on the current branch:
1
git checkout --orphan <new-branch-name>


  1. Remove all files from the working directory and the index:
1
git rm -rf .


  1. Add and commit any new files that you want to include in the orphan branch:
1
2
git add .
git commit -m "Initial commit on orphan branch"


  1. Push the orphan branch to the remote repository (if necessary):
1
git push origin <new-branch-name>


Now you have successfully created a full orphan copy of the current branch in git.