Question

I have several local git repositories which are logically separate projects. When each project is finished I want to make the entire repository a branch of an "archive" repository, just in case bugs appear in the future. Since, ultimately, each repository will be part of the archive repository I thought that I'd push each repository to a remote copy of the archive repository from the very beginning.

So I have separate repositories: archive, A, B, ... and I want to push them to a remote which will look like:

archive -- A as a branch
        \---B as a branch

and so on.

I've searched through the git documentation, and on the net, and came up with the following alias for doing this:

backup = "!for br in $(git branch --column|sed 's/*//';); do git push archive ${br}:$(basename $PWD)/${br}; done"

So now, from A say, I can just do:

git remote add archive ssh://git@bitbucket.org/.../archive.git
git backup 

This pushes each branch X in A are to a branch A/X on the remote. Unfortunately, each branch in A is a separate disconnected branch on the remote repository, so I have lost the history in A which isn't really what I want.

Is there a way of pushing all of the branches on A to a single branch (or rather a tree) on the remote repo? Or is my entire approach misguided and there is a better way to do this?

Cheers, Andrew

Was it helpful?

Solution 2

I found a question about merging repositories on stackoverflow and the answer by Olivier Verdier solves my problem: I just need to add the finished repo into the archive repository:

$ git remote add A /path/to/A
$ git fetch A
$ git remote add B /path/to/B
$ git fetch B

Done.

OTHER TIPS

Sounds like you're making a huge effort on something that is totally awkward. Git is a perfectly fine version control system, there's no reason why you'd want to push branches to some "archive" repository.

The right way to do this is to use tags to mark stable releases of your code.

You can then create tagged versions of your code like so:

$ git tag -a v1.0 -m "First stable release"

And then access that release using the usual syntax you would use for any git operation that receives a commit/tag object:

$ git checkout v1.0

See http://git-scm.com/book/en/Git-Basics-Tagging for more info on how to use tagging in git.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top