Edit

Share via


Move Git repositories to another project with full-fidelity history

Azure DevOps Services | Azure DevOps Server | Azure DevOps Server 2022

Git logo

If you plan to consolidate multiple Azure DevOps projects into one, you're probably wondering what you should do with all the repositories:

  • Should you move projects or merge them?
  • Should you keep the history or just the most recent projects?

Prerequisites

Category Requirements
Project access Member of a project.
Permissions - View code in private projects: At least Basic access.
- Clone or contribute to code in private projects: Member of the Contributors security group or corresponding permissions in the project.
- Set branch or repository permissions: Manage permissions are permissions for the branch or repository.
- Change default branch: Edit policies are permissions for the repository.
- Import a repository: Member of the Project Administrators security group or Git project-level Create repository permission set to Allow. For more information, see Set Git repository permissions.
Services Repos enabled.
Tools Optional. Use az repos commands: Azure DevOps CLI.

Note

In public projects, users with Stakeholder access have full access to Azure Repos, including viewing, cloning, and contributing to code.

Category Requirements
Project access Member of a project.
Permissions - View code: At least Basic access.
- Clone or contribute to code: Member of the Contributors security group or corresponding permissions in the project.
Services Repos enabled.

What's the scenario?

As shown, you need to move the MigrationDemo repo from FabrikamOld to the new Fabrikam team project.

Screenshot that shows the move repo scenario.

How do I move?

You have two options for moving, as outlined here. Import functionality is easier, but it's available only in Azure DevOps Services and Team Foundation Server 2017 Update 1 and later.

Use Import Git repository functionality

When you use the Import Repository feature, you can import a Git repository to your team project from Team Foundation Server, Azure Repos, or any other Git source code provider like GitHub. For more information, see Import a Git repository to a project.

Manually migrate the Git repo

Create an empty Git repo

From the CODE Explorer, select the repo name. Select New Repository from the list, select Git as the type, and give it a name.

Screenshot that shows creating a new repo.

After the repo is created, step-by-step instructions appear to help you get started. Copy the clone URL to your clipboard.

Screenshot that shows the pane to add new repo information.

Important

Clear the Automatically create links for work items mentioned in a commit comment option if you plan to import from a different project collection or a foreign Git repository. Otherwise, Azure DevOps associates the commits to existing work items of unrelated team projects in the team project collection.

Screenshot that shows new repo options.

Mirror the repository

Switch to a developer command prompt and path to your local (source) repository for the MigrationDemo repo in FabrikamOld. Run the git clone --mirror command by using the clone URL. The command line is git clone --mirror https://demo-fabrikam.visualstudio.com/DefaultCollection/Fabrikam/_git/MigrationDemo.

The clone --mirror command is redundant in this case because the remote repository is bare. It's used here as a safe and easy way to set up the remote.

Screenshot that shows that the Git clone command is done.

Push the repo

Run the git push command to push the local changes to the remote (target) repo.

Screenshot that shows that the Git push command is done.

The --mirror option is used with both the clone and push commands. The option ensures that all branches and other attributes are replicated in the new repo.

Validate the new repository

Switch to the Azure DevOps web portal and validate the new repository and the history in the CODE hub.

Screenshot that shows repo validation in CODE Explorer.

Verify that all your branches were moved over to the new repo.

Configure the new repo

Verify that the permissions and policies are correctly configured for the new repo. You can configure the security after you create an empty Git repo or at this stage. Reconfigure your builds to connect with the new repo. Lastly, notify users of the original repo to update their remotes in Visual Studio or by running the git remote set-url origin command.

> git remote set-url origin https://demo-fabrikam.visualstudio.com/DefaultCollection/Fabrikam/_git/MigrationDemo

Important

Remember to clean up the original project by either deleting the repo (be careful, there's no undo) or locking the branches so that no one accidentally keeps updating it.

For more information on planning your team project collections and team projects, see TFS Planning, Disaster Avoidance and Recovery, and TFS on Azure IaaS Guide.