0

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

Andrew
  • 281
  • 4
  • 16
  • Why not just use `git tag` to properly tag stable releases of your different projects? – Yuval Adam Nov 21 '13 at 13:02
  • Your end product would be a "repo full of repos", where, to get "repo Q" out of "repo full of repos", you must first copy the entire repo full of repos, then strip out all the unwanted repos leaving only repo Q, then rename all the branches back to their original names. This is not what git is designed for and it will be awkward and slow. It would be better to archive your repo to a (dir|folder)-full-of-repos. Then, to get "repo Q" out of "(dir|folder) full of repos" you simply copy "dir/repoQ" and you're done. – torek Nov 21 '13 at 17:41

2 Answers2

0

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.

Yuval Adam
  • 161,610
  • 92
  • 305
  • 395
  • I use tags a lot but here it doesn't make sense as they are different projects. I also don't want to push a branch to a remote repository, I want to make the whole repository a branch of another repository. That is, once a project is finished I want to move it into a repository of repositories. – Andrew Nov 21 '13 at 17:13
  • Not sure what you're trying to do here - it's unorthodox for sure - but sounds like you found your answer. – Yuval Adam Nov 22 '13 at 21:15
0

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.

Community
  • 1
  • 1
Andrew
  • 281
  • 4
  • 16