How to Move to a Different Git Repository Provider

Updated 3 months ago by Copado Solutions

Moving a Git Repository

Git makes it easy to clone repositories and to switch between Git providers such as GitHub, GitLab, Bitbucket, Azure DevOps, or AWS CodeCommit. Because Copado connects directly to the Git repository, you also need to update Copado if you migrate a repository. Since the development team and release process depend on the repository, this change needs to be done carefully but quickly.

These are the factors to consider:

  • User access to the new repository.
  • Migrate and test the new repository.
  • Update Copado to connect to the new repository.
  • Bonus: Create a backup repository if it is not yet available.

Once you start to create a repository, you need to be ready to switch it in Copado too, so perform connection testing before starting the switch with an empty repository. 

A good time is probably Thursday afternoon/evening or Friday if there are no important deployments happening on Friday. This way you can change the setup if something goes wrong.

You can always roll back by simply providing the old clone url/username/password/base urls, so take a note of the values on the old Git repository record.

While you should take time to test beforehand, the final migration can be done in roughly 30 min.

Perform a test-commit and validation after the switch is done.

User Access

After gaining access to your new provider, ensure:

  • Grant access to your users.
  • If you have a group or team functionality, add them to the group/team so that you have an easy way to provide access to repositories.
  • Ensure your users are able to work/commit on feature and promotion branches (at least).
  • Create a system user, which will be used as the primary connection for Copado.
  • Once the repository is created, grant the group/team collaboration (or edit) access to the new repository.

Create a New Repository with the Old Contents

In order to maintain work in progress we need to ensure commit Ids and branch names stay the same as before. The easiest way to do this is to import your old repository.

Here you will find instructions on how to import your old repository into some widely-known repository providers.

If you want to import your repository into Bitbucket follow these steps:

  1. Go to Bitbucket's home page.
  2. Click on the + sign on the left of the screen.
  3. Select Repository under Import.
  4. Provide your clone url for the old repository:

If you want to import your repository into GitHub follow the steps below:

  1. Log in to your GitHub account.
  2. Navigate to the Repositories tab and click on New on the left of the screen.
  3. In the new dialogue, click on the Import a repository hyperlink on top.
  4. Provide the clone URL of the old repository, set the owner and the privacy settings and click on Begin Import:

If you want to manually export/import your repository, follow these steps:

  1. Create a new empty repository in your new repository provider. Make a note of the clone url.
  2. Open your command line and run the following commands:
    1. Clone your old repository fully:
      git clone --mirror <cloneURLofOldRepo> <nameOfTemporaryFolde    
    2. Go to the directory of the cloned repository:
      cd <nameOfTemporaryFolder>/
    3. Perform a push of the folder contents to the new repository target:
      git push --mirror

Verify the results after the command is finished in your target repository.

Connection with Copado

Your goal here is to know that connection is not an issue, so it needs to be tested before. Also, you want to change as little as possible in your current setup.

  • Create a new repository in your Git repository provider. Make sure to copy the clone url. This repository will be dropped after the test, so there is no need to set up gitignore or branches.
  • Create a new Git Repository record in Copado (name it, for instance, New Repo Test).
  • Use the clone url and provide the username/password.
  • Don’t care about the rest, you will not work with this repository record.
  • If you see a green bar after the record is created, all good. 
  • If not, resolve connection issues. (IPs whitelisted? Correct Username/Password? Can you clone it outside of your network?...)
  • Delete the testing repository in Git and the Git Repository record in Copado.
Connecting to Copado
  1. Go to the Git Repository record in Copado, which is currently used for your main pipeline.
  2. Modify the URI, username/password and the base URLs to fit your new main repository (the one you created for testing before).
  3. You can leave the rest as it is.

Bonus: Create a Backup Repository

If you don’t have a backup repository, now is the time to create one.

  1. Create a new repository in Git with a name that identifies it as a backup repository.
  2. Initialize the repository with an empty .gitignore file.
  3. Create branches for the main organizations in your pipeline. It is ok if they are empty.
  4. Create a Git Repository record in Copado linked to the new Git repository.
  5. Create a set of Git Snapshot records linked to the backup repository:
    1. Name the snapshots so that it’s visible they are for backup (e.g. DEV_BACKUP).
    2. Set the frequency to Daily.
    3. Git Repository: Select the backup repository you have created.
    4. Branch: The name of the branch as defined in the repository.
    5. Git Snapshot Permissions: Allow Snapshots Only.
    6. Execute the snapshot once you create them.

These snapshots will include all the metadata in an organization and will run automatically in the future on a daily basis.

How did we do?