3

I have several closely related projects in a directory, and I want them all to be tracked with the same git repository.

Right now I have two directories, thing1 and thing2, in a parent directory things. Each directory has its own .git. I want to have one .git in the things directory that includes all of the history from both thing1 and thing2.

My question is essentially the same as this one, but with two (or in general any number of) directories instead of one.

Community
  • 1
  • 1
Dan
  • 10,845
  • 11
  • 46
  • 75
  • 1
    This is very similar to [This][1] question on stackoverflow. [1]: http://stackoverflow.com/questions/1425892/how-do-you-merge-two-git-repositories – Andrew Spott Oct 27 '11 at 20:34

1 Answers1

2

Use filter-branch to move all history in the repos to where you want them to be in the resultant repository. In one of the repos, add a remote that points to the other one. Do a fetch and you'll have both in the same one. You will have separate branches for the work in each. Do a merge and from then on, you will have changes to both tracked in a common branch - if that's what you want to do.

Hope this helps.

Adam Dymitruk
  • 109,813
  • 21
  • 138
  • 137
  • Could you point to some documentation for `git filter-branch`? – Dan Sep 22 '11 at 03:45
  • 1
    I don't think filter-branch is needed in your case at all. Just follow what Adam said from the 2nd sentence onwards. – holygeek Sep 22 '11 at 04:00
  • I'm an extreme git novice. What does "add a remote" mean? What type of merge should I use? – Dan Sep 22 '11 at 05:16
  • 1
    You do want to do the filter branch as you may have some files that are called the same thing. Filter branch will allow you to move your entire history as if you had done your work one level deeper. – Adam Dymitruk Sep 23 '11 at 01:02
  • 1
    to add a remote is to register a url or file location of another repository so that you can push changes to that other repository from the current one. See the manual page for `git remote`. – Adam Dymitruk Sep 23 '11 at 01:03
  • Do I need to `git init` the parent directory before I `git filter-branch`? – Dan Sep 23 '11 at 04:43
  • you filter branch on a repository that already has history. It edits history to make your work look like you did it in another folder. – Adam Dymitruk Sep 23 '11 at 05:12
  • `kernel.org` is down right now, so I can't access the `filter-branch` documentation. What actual command should I use? – Dan Sep 23 '11 at 22:06
  • it should be back up now. If it happens again, hit "cached page" in google. – Adam Dymitruk Sep 26 '11 at 19:58
  • Thanks for answering all of the questions I had in your comments! – Dan Sep 27 '11 at 21:58