Last active
December 11, 2015 12:18
-
-
Save vmbrasseur/4600063 to your computer and use it in GitHub Desktop.
A repo is a subdirectory but you'd rather the repo were the parent directory. How do you do that?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I need a git power user to confirm that the steps below are correct before I pull the trigger and risk | |
completely hosing my repo... | |
I'm referencing this github helpdoc: https://help.github.com/articles/working-with-subtree-merge | |
Assume a directory structure of (note: directory names have been changed to protect the innocent): | |
Animals/ | |
Apes/ | |
Cats/ | |
.git/ | |
Dogs/ | |
Rodents/ | |
Long ago you created a github repo for Cats. Now you'd rather you had the repo on Animals to include | |
all subdirectories, not just Cats. You'd like to move the Cats repo and history into Animals. So, in | |
the directory view, you'd rather the above were this: | |
Animals/ | |
.git/ | |
Apes/ | |
Cats/ | |
Dogs/ | |
Rodents/ | |
How do you do this while still maintaining the history of the Cats repo? | |
Step 1: Get Cats out of the way | |
$ cd Animals | |
$ mv Cats .. | |
Step 2: Create a repo in Animals | |
$ cd Animals | |
$ git init | |
$ touch .gitignore | |
$ git add .gitignore | |
$ git commit -m "Adding .gitignore to new Animals repo" | |
Step 3: Clone Cats | |
$ git remote add -f Cats git://github.com/yournamehere/Cats.git | |
Step 4: Merge Cats with Animals | |
$ git merge -s ours --no-commit Cats/master # check what merge will do before committing | |
$ git read-tree --prefix=Cats/ -u Cats/master # read the Cats tree info into the index | |
$ git commit -m "MOAR CATS" # commit them kitties to the Animal repo | |
Then add the Apes, Dogs and Rodents subdirs to the new Animals repo. This is standard directory adding | |
stuff and requires no special handling. | |
Once Cats is merged into Animals, you can delete the old Cats repo. |
Ah, ha! git-subtree is a contrib script that apparently macports installs by default.
A quick & dirty, stone knives & bearskins approach:
- Change the Cats repo's name to Animals, locally, on remote host, etc.
mkdir Cats
git mv foo Cats/
- commit
- add Apes, Rodents, etc.
- profit?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well, if you're going to do it the hard way... yeah, that looks like it'll do what you want. You really should look into getting a recent Git on that machine, though. Tons of really nice improvements since then. Try to get something in the 1.8.x series (1.7.7 is from September 2011). I use macports for my stuff instead of homebrew