sub_o sub_o -4 years ago 164
Git Question

How to transplant branch from one repository to a new one without history?

I have an existing repository that has reached a certain storage cap.

However, now I want to transplant several branches from the old to a new repository, without the baggage of old history (since the git history is the culprit of that storage issue)

Is there any git command or sequence of commands that could help me do that?

e.g

cd old_repo/
git checkout old_repo_old_branch

git remote add origin new_repo
git push origin new_repo_new_branch ?? // Does this preserve the history


Edit: Thanks in advance, pardon me for my rudeness.

Answer Source

git push origin new_repo_new_branch ?? // Does this preserve the history

Yes, new_repo_new_branch preserves the history.

You can checkout a new branch with --orphan flag. This will erase all previous commit histories.

$ cd old_repo/
$ git checkout old_repo_old_branch

$ git checkout --orphan new-branch       # checkout a new branch (say, new-branch) cleaning all previous commit histories
$ git log                                # see commit history is empty

$ git remote add newrepo <new-repo-url>  # add a new remote (say, newrepo) with new-repo-url
$ git push -u newrepo HEAD               # push to newrepo/new-branch 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download