TIL: Merging git repos
For whatever reason I don’t like having a bunch of small repos under my github account. At the start of learning go I was creating a bunch of little folders for projects and committing them into github. Looking over my page, it was gettin pretty sloppy and hard to tell what was somehting worthwhile that I created and what was just lessons. So I decided I’d do a little house keeping
In my case I had about 6 small repos sitting inside of my main
go/src/github/fuzzylimes path that already had some work/commits done to them. Rather than just tossing that work and losing this history, I was looking for a way to merge those files in and get them coppied over.
A quick google search landed me at this stackoverflow answer.
Before using the flow on this page, there’s a few extra things that need to be done first:
mkdir -p my/new/repo
git add .
git commit -m "Initial commit"
git rm tmp.txt
git commit -m "Cleanup"
Now that the repo has been started, you’re good to move on to merging over the repos into the new repo. The flow is like this:
git remote add project path/to/project
git fetch project
git merge --allow-unrelated-histories project/master
git mv * project
git commit -m "Moved to correct subfolder"
git remote remove project
Rinse and repeat until all of the repos have been added over to the new one.
Problem with subfolders
If you’ll notice, I wasn’t able to get the files over into their subfolder in one go. When I tried this method from within the subfolder, I would always get error messages telling me that the path didn’t exist. Not sure why that was, and I couldn’t find any answers for it on the page. So I bit the bullet and did the transfer manually.
If you can find a way to do it in one go, more power to you!