Home > Software design >  Copy git repository and keep timeline / file history
Copy git repository and keep timeline / file history

Time:02-25

i have a quite simple use case (i guessed so far) but it turns out to be more problematic than i thought.

So we have an existing repo in Bitbucket "RepoA" and wanted to keep working on a copy of that repo called "RepoB". We wanted to work on a clone because we wanted to keep the file history that happened in RepoA without changing RepoA anymore.

So what i did/tried:

  1. I cloned RepoA (tried a normal clone as well as a --mirror clone)
  2. I changed the remote of the clone to "RepoB" which was blank at that time
  3. I pushed everything into the remote RepoB

So it looked fine at first, in Bitbucket the file history contained both changes made in RepoB as well as the changes which happened in RepoA. In addition the whole commit history was also available.

But when i was using VSCode and working on the local repo, the timeline/file history only contains the commits which have been made in RepoB.

Maybe this is quite simple to achieve but i couldn't figure it out so far.

CodePudding user response:

As you mentioned that you have used a mirror but didn't achieve the result. Here I have summarized steps for mirroring

1. Start by creating a mirrored clone of your old repository

  • git clone --mirror old-repo-url new-repo

2. Remove the remote reference to the original/old repository

  • cd new-repo
  • git remote remove origin

3. Add the remote reference for the new repository

  • git remote add origin new-repo-url

4. Push everything to the new repository

  • git push --all
  • git push --tags

5. Clone the new repository, May you haven't clone the new repo after mirroring

  • cd ..
  • rm -rf new-repo
  • git clone new-repo-url new-repo

This is tried and tested.

  •  Tags:  
  • git
  • Related