Migrating existing Git repositories

When it comes to migrating sources, moving to another location for hosting Git repositories is straightforward, compared to other migrations. Let's learn how to do this:

  1. First, clone the existing repository to your local computer. Please note the dot at the end—this will place the repository in your current directory:
git clone https://{organization}@dev.azure.com/{organization}/{teamProject}/_git/{repository} .
  1. Add another remote that refers to the new, empty repository that you want to move the sources to:
git remote add migrationTarget https://{organization}@dev.azure.com/{organization}/{teamProject}/_git/{newRepository}
  1.  Finally, you push the changes to this new repository. You must do this separately for every branch you want to move next to the master:
git push migrationTarget master

Meanwhile, other developers might have continued working with the existing repository.

  1. To include those in the new repository as well, you must fetch them to your local computer from the original repository and then push them to the new repository. Again, repeat this for every branch:
git fetch origin master
git push migrationTarget master
  1. Repeat these last two commands until there are no developers working on the source repository anymore.
  2. After a successful migration, it is often best to remove the old repository. This prevents anyone from continuing to work there by accident.

The preceding steps will work for any Git-to-Git migration.

Now, if you specifically want to migrate to an Azure Git Repo, you can also use the import functionality that is included with Azure DevOps. To do this, follow these steps:

  1. Navigate to Git Repos and optionally create a new Git repository first.
  2. Choose to Import an existing repository.
  1. Provide the requested information.
  2. Click on Import to start importing the repository.

The following screenshot illustrates these steps:

The disadvantage of this approach is that you cannot keep pushing changes from the source repository to the new repository. This means that all other developers on your team must make sure that they move their changes over on their own or do not have any pending work while you migrate the repository.