REPO SPRAWL OCTOBER03,2023
A short tutorial on how to merge git repos
---

Preamble:

I've been automating my virtual machine workflow recently (spin up, auto ssh, test settings, destroy) and have a number of repos separated by specific tasks (get-docker, get-virt-manager, etc). Due to this I have a few repos with simple files to do basic tasks that I would like to pull together into one repository. My goal today is to merge all of these script repos into a single repo called scripts.

Before You Start:

I highly recommend removing any conflicts BEFORE you start merging.
1. Check for directory conflicts. If you have a directory named "spaghetti" in the root directory of two of the repos you plan to merge you should change one or both to more explicit names OR put them within another directory inside of the pre-merged repos.
2. Check for file conflicts. your README's will conflict. I temporarily changed the names of my existing README's and did the file organization after merging. If you have two files with the same name in your root directory they will conflict. Either put them in sub-directories or change their names. If you followed step one you shouldn't have to worry about this happening deeper in your directory tree.
3. Great. You've successfully preempted the most difficult part of merging repositories.

Getting Started:

The first step of wrangling all these automation repositories into one is to get a list of all the repos that are going to get merged.
There are two ways to do step two.

1. Have an existing repo which you will merge all repos into.
2. Create an empty repo as the target repo (my case).

No existing repos have a simple and broad enough name to be the orchestration repo in my case. They all have names like "get-docker-on-ubuntu-vm" or something just as specific. In my case scripts will be the name of the new repo.
After you have selected which scripts will be merged and either selected or created the target repository, move on to the next section.
---
if you aren't sure about a repo, leave it out. You can just add it later.

Preparation:

Lets say I have three repositories: repo-x, repo-y, and repo-z that I want to merge together. In my case (number two from above) - I also need an empty repo ( here's mine: scripts ) to merge these into.
LOOK FOR CONFLICTS before you start.
1. Initialize the new repo in the directory of your choosing. In my case, it's simply scripts. You can also create it on github.com and pull from there.
$ git init
$ touch README.md
$ git add README.md
$ git commit -sm "initial commit"
$ git remote add origin https:/github.com:username/repo-a
$ git push origin main

2. Create a branch. This is not a necessity, but is good practice.
$ git checkout -b branch-name

3. If you run into conflicts you will have to deal with them individually. That will probably be tedious and annoying. Why didn't you listen earlier?

Merge:

Be sure that you are in the directory of the main repo you are planning to merge the others into. Add the remote git repo:
$ git remote add -f repo-x [email protected]:username/repo-x.git

Merge the repos:
$ get merge repo-x/main --allow-unrelated-histories

If you don't add the --allow-unrelated-histories flag you will get a fatal error.

GREAT! Now repeat the merge section as many times as you have repositories you want to merge.