Copy single branch from git repo and make it independent

740 Views Asked by At

I have a git repo lets say "MyRepo", with following structure, branch1, branch2, tags, etc. I want to create a new git repo, "EasyStart" that has the code and history of just branch2 and I don’t want anything else like branch1, tags etc from MyRepo. And I don’t want any other links or connectivity with MyRepo. So once the EasyStart repo is setup it only has history and code of branch1 and hence forth any updates/changes done on EasyStart will not reflect in MyRepo and vice versa. How do I achieve this?

1

There are 1 best solutions below

2
On

You can achieve this by using a temporary repo for clean up. The steps would be:

  1. clone the original repository
git clone <old repo>
  1. push it to a new temporary repository
git remote set-url origin <temp repo>
git remote -v
git push origin
  1. delete all branches that you want (local and remote)
git fetch
git push origin --delete branch1
git branch -D branch1
  1. delete all tags (local and remote)
git fetch
git push origin --delete $(git tag -l)
git tag -d $(git tag -l)
  1. remove the remote and add your new (final) remote and push to it. This should give you a clean start.
git remote set-url origin <temp repo>
git remote -v
git push origin