2

I have two git repositories. Both have a master branch that is manually kept in sync with a different branch of the same CVS repository, and a decent amount of feature branches.

For example

  • Git repository OLD:
    • master (manually tracking the CVS branch OLD_VERSION)
    • feature-abc-backport
    • feature-xyz
  • Git repository CURRENT:
    • master (manually tracking HEAD of the CVS repository)
    • feature-abc
    • feature-123

I now want to import all branches from OLD into CURRENT, with some prefix added (e.g. OLD-master, OLD-feature-abc-backport, OLD-feature-xyz). Is this possible?

Jens Müller
  • 302
  • 4
  • 13

1 Answers1

2

Importing a branch is possible.
Manage it once imported can be trickier.

Importing:

cd current
git remote add old /url/to/git/old
git fetch old
git branch --track old_master old/master
git branch --track old_feature-abc-backport old/feature-abc-backport
git branch --track old_feature-xyz old/feature-xyz

Managing:

The question is: are the commits of the git 'old' repos the same as the ones in the git 'current' repo?
If yes, then you can merge an old_xxx branch in a current branch, since the delta would be limited.


Actually, I would like to do the import mainly for archival purposes, at least in the first step. When a branch goes out of maintenance

Then a simple fetch is enough:

All the branches from old will be immediately references as old/abranch: no need to create a local branch with a 'old_' prefix.
Their full history will be available in your current repo (after the fetch), and each old branch HEAD will be references by the remote tracking branches (created by the fetch) in refs/remotes/old/abranch.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Actually, I would like to do the import mainly for archival purposes, at least in the first step. When a branch goes out of maintenance, I will never have to work on it again. The idea is to throw away the old Git repository. So I just want to "copy" the branches, it is not necessary to pull them again later. I don't want to type one line per branch, as in your suggestion. Is there a way without it? I hope we will switch to Git entirely in the near future, which will make my whole workflow much easier ... – Jens Müller Aug 13 '13 at 13:11
  • Regarding your question: No, they are not. I update the master branch of the respective repo from CVS from time to time when necessary, individually for each Git repository. The contents are (slightly) different anyway, because the Git repositories track different branches of the same CVS repository. I think, however, that they are similar enough so that putting them into one Git repository saves quite some space. – Jens Müller Aug 13 '13 at 13:13
  • @JensMüller then the `git fetch` step is enough. I have edited my answer to address your comment. – VonC Aug 13 '13 at 13:16
  • What if no, the commits of `old` are different than `current`? – Sandra K May 03 '18 at 16:40
  • @SandraK That won't matter: old commits are fetched in the local repo /old namespace. Those commits can have some in common or none in common with the ones from current. They are still fetched. – VonC May 03 '18 at 22:04
  • 1
    Awesome. My question got marked as duplicate by this. +1. Thanks. – Sandra K May 04 '18 at 05:59