1

I have a repo on Github in which I intended to include a second Github repo (also mine) as a subtree. Unfortunately my inexperience means this failed so all the work I've committed since January has gone into the history of the main repo.

How can I copy this history into the second repo then change the main project to use it as a subtree?

Edit: One of the comments (now deleted) asked why I didn't just use a single repo. The main repo is private but the second repo is public - I'm trying to share what I can.

0

1 Answer 1

1

A friend of mine pointed me to Moving files from one git repository to another, preserving history. The filter-branch instruction didn't work for me, possibly because my repo has no branches? Anyway, what I did was:

git clone <git repository A url>
cd <git repository A directory>
git remote rm origin
git filter-branch --subdirectory-filter <directory 1> --

This gave me a repo that only had the changes in the subdirectory. I then merged this into my second repo:

git clone <git repository B url>
cd <git repository B directory>
git remote add repo-A-branch <git repository A directory>
git pull repo-A-branch master
git remote rm repo-A-branch

I then used filter branch to remove the subdirectory from the main repo:

git filter-branch --tree-filter 'rm -rf <bad subdirectory>' --prune-empty HEAD

Finally I followed The power of Git subtree to add the updated second repo to the first as a subtree.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.