

- #Git add remote repository to a subdirectory update#
- #Git add remote repository to a subdirectory code#
(Since we did a rename, you have to do “git log –follow ” to see that history, but that’s true for any file rename operation, not just for our repo-merge.) Now we have all the files from OldA and OldB in repository New, sitting in separate subdirectories, and we have both the commit history and the individual file history for all files. Git commit -m “Move old_b files into subdir” # Move the old_a repo files and folders into a subdirectory so they don’t collide with the other repo coming laterĭir –exclude old_a | % # Clean up our dummy file because we don’t need it any more # Merge the files from old_a/master into new/master # Add a remote for and fetch the old repo # Before we do a merge, we have to have an initial commit, so we’ll make a dummy commit # Assume the current directory is where we want the new repository to be created

Make an initial commit because we need one before we do a merge.Ī Powershell script for these steps might look like this:.The basic idea is that we follow these steps: Fortunately, after much research and trial-and-error it turned out that it’s actually very easy to do what I was trying to do and it requires just a couple of straightforward git commands. I didn’t need the ability to extract changes and ship them back anywhere because my old repositories would be retired. I wanted to glue to repositories together and have them look as though they had always been one repository all along.

This is generally not a problem for the “import an external library” scenario but I was trying to do something different. you can view the commits in the DAG) but if you try to view the history for a specific file in your sub-project all you’ll get is one commit for that file – the subtree merge. You can see the history of commits for those files in aggregate (i.e.
#Git add remote repository to a subdirectory code#
One side effect of this is that when you import the source code using a subtree merge all of the files show up as newly added files. For instance, do a web search on this subject and you’ll get a lot of information about git submodules or subtree merges, both of which are kind of complex and are designed for the situation where you’re trying to bring in source code from an external project or library and you want to bring in more changes from that project in the future, or ship your changes back to them. The bad news is that there are a few different ways to do it and some of them end up with a less desirable result (at least for our purposes) than others. Since a repository in Git is just a directed acyclic graph, it’s trivial to glue two graphs together and make one big graph. The good news is that Git makes this sort of thing very easy to do. However, we wanted to preserve all of the change history from each repo and have it available in the new repository. Over time we realized that there was no good reason for this arrangement and was just a general hassle and source of friction, so we decided to combine our two repositories into one repository containing both halves of the code base, with each of the old repositories in its own subdirectory. Following are the commands, modified for my use case : Initial setup.A while ago my team had code for our project spread out in two different Git repositories. but, it is what it is.Īfter much struggling with git, subtree and git-subtree, I ended up finding this - it basically sets up separate branches from tracking remote, the particular sub-directory, and uses git subtree contrib module to pull it all togther. Ideally their template should be a separate repo added to jsdoc via a submodule - this way I could fork it and things would be much easier.
#Git add remote repository to a subdirectory update#
In this particular case, I'm interested in bringing in the 'default' template of jsdoc as a sub-directory in my project so I could potentially make changes to the markup it genereates while also being able to update from upstream if there are changes.
