Редагувати

Поділитися через


Clone an existing Git repo

Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019

Visual Studio 2019 | Visual Studio 2022

You can create a local copy of a remote Git repo by cloning it into a local folder on your computer. Cloning a remote repo downloads all commits on all branches of the repo, unless you use the --single-branch clone option. Cloning links each branch in your new local repo with the corresponding branch in the remote repo. That way, when you push to share your local branch changes with your team, the corresponding remote branch is updated. Similarly, when you pull to update your local branch with changes made by your team, updates from the corresponding remote branch are retrieved. The remote repo can be an Azure Repos Git repo, a GitHub repo, or other hosted Git repo.

This article provides procedures for the following tasks:

  • Get the clone URL for an Azure Repos Git repo
  • Get the clone URL for a GitHub repo
  • Clone an Azure Repos Git repo
  • Clone a GitHub repo
  • Clone any Git repo
  • Open a Visual Studio solution from a cloned repo

For an overview of the Git workflow, see Azure Repos Git tutorial.

Prerequisites for access to Azure Repos

  • Repos must be enabled in your Azure DevOps project settings. If the Repos hub and associated pages don't display, see Turn an Azure DevOps service on or off to reenable Repos.

  • To view code in private projects, you must be a member of an Azure DevOps project with Basic access level or higher. For public projects, everyone can view the code.

  • To clone or contribute to code for a private project, you must be a member of the Contributors security group or have the corresponding permissions set. For public projects, anyone can clone and contribute code. For more information, see What is a public project?

    Note

    For public projects, users granted Stakeholder access have full access to Azure Repos.

  • Repos must be enabled in your Azure DevOps project settings. If the Repos hub and associated pages don't display, see Turn an Azure DevOps service on or off to reenable Repos.

  • To view code, you must be a member of the Azure DevOps project with Basic access or higher. If you aren't a project member, get added.

  • To clone or contribute to code, you must be a member of the Contributors security group, or have the corresponding permissions, in the project you want to change.

Get the clone URL of an Azure Repos Git repo

Typically, you need to know the clone URL of the remote repo that you want to clone. The clone URL uniquely identifies the remote repo.

Note

When you're signed into an Azure DevOps project, Visual Studio supports searching for and cloning project repos without needing to know the clone URL.

  1. From your web browser, open the team project for your Azure DevOps organization, and then choose Repos > Files to open the Files view.

    Screenshot of the Azure DevOps project page.

  2. In the Files view, choose Clone to launch the Clone Repository popup.

    Screenshot of the Clone button on the Azure DevOps repo page.

  3. Copy the clone URL from the Clone Repository popup.

    Screenshot of the 'Clone Repository' popup on the Azure DevOps project site.

Note

With Azure DevOps Services, the format for the project URL is dev.azure.com/{your organization}/{your project}. However, the previous format that references the visualstudio.com format is still supported. For more information, see Introducing Azure DevOps, Switch existing organizations to use the new domain name URL.

Get the clone URL of a GitHub repo

Typically, you need to know the clone URL of the remote repo that you want to clone. The clone URL uniquely identifies the remote repo.

Note

When you're signed into GitHub, Visual Studio supports searching for and cloning GitHub repos without needing to know the clone URL.

  1. Open a browser and navigate to your GitHub account, select the Repositories tab, and choose the repository to clone.

    Screenshot of the repository page on the GitHub site.

  2. On the GitHub repository page, choose Code to launch the Clone popup. Copy the clone URL from the Clone popup.

    Screenshot of the Clone popup on the  page on the GitHub site.

Clone an Azure Repos Git repo

By signing in as a member of an Azure DevOps project, you can clone private repos that are accessible to you, and public repos. Visual Studio supports search, clone, and sync operations on repos that are accessible through authentication.

Note

You can clone a public Azure Repos Git repo without signing in as a member of its parent Azure DevOps project. To clone a public Git repo without signing in, see Clone any Git repo and then connect to a project in Azure DevOps.

Visual Studio 2022 provides a Git version control experience by using the Git menu, Git Changes, and through context menus in Solution Explorer. Visual Studio 2019 version 16.8 also offers the Team Explorer Git user interface. For more information, see the Visual Studio 2019 - Team Explorer tab.

  1. From the Git menu on the menu bar, choose Clone Repository to open the Clone a repository window.

    Screenshot of the 'Clone Repository' option in the Git menu in Visual Studio.

  2. In the Clone a repository window, select Azure DevOps under Browse a repository to open the Connect to a Project window.

    Screenshot of the 'Clone Repository' window in Visual Studio.

  3. In the Connect to a Project window, sign in to Azure DevOps and choose the remote repo you want to clone. You can use the search box to filter the list of remote repos. If you don't see the remote repo, select Add Azure DevOps Server to add the server that hosts the repo. Verify the local folder path where you want the local clone to be created, and then select Clone.

    Screenshot of the 'Connect to a Project' window in Visual Studio.

After you've cloned a remote Git repo, Visual Studio detects the local clone and adds it to the list of Local Repositories in the Git menu.

Screenshot of the 'Local Repositories' option in the Git menu in Visual Studio.

Clone a GitHub repo

By signing into GitHub or using SSH authentication, you can clone private repos that are accessible to you, and public repos. Visual Studio supports search, clone, and sync operations on repos that are accessible through authentication.

Note

You can clone a public GitHub repo without signing in to GitHub or otherwise authenticating. To clone a public Git repo without signing in, see Clone any Git repo.

  1. From the Git menu on the menu bar, choose Clone Repository to open the Clone a repository window.

    Screenshot of the 'Clone Repository' option in the Git menu in Visual Studio.

  2. In the Clone a repository window, select GitHub under Browse a repository to open the Open from GitHub window.

    Screenshot of the GitHub option in the 'Clone Repository' window in Visual Studio.

  3. In the Open from GitHub window, sign in to GitHub and choose the remote repo you want to clone. You can use the search box to filter the list of remote repos. Verify the local folder path where you want the local clone to be created, and then choose Clone.

    Screenshot of the 'Open from GitHub' window in Visual Studio.

After you've cloned a remote Git repo, Visual Studio detects the local clone and adds it to the list of Local Repositories in the Git menu.

Screenshot of the 'Local Repositories' option in the Git menu of Visual Studio.

Clone any Git repo

You can clone any Git repo that's accessible to you by using the clone URL of the repo.

  1. From the Git menu on the menu bar, choose Clone Repository to open the Clone a repository window.

    Screenshot of the 'Clone Repository' option in the Git menu in Visual Studio.

  2. In the Clone a repository window, enter the clone URL of the remote Git repo that you want to clone, verify the local folder path where you want to create the local clone, and then choose Clone.

    Screenshot of the 'Clone a repository' window in Visual Studio.

After you've cloned a remote Git repo, Visual Studio detects the local clone and adds it to the list of Local Repositories in the Git menu.

Screenshot of the 'Local Repositories' option from the Git menu in Visual Studio.

Open a Visual Studio solution from a cloned repo

  1. Choose the File > Open > Project/Solution from the menu bar, and select the solution file to open.

    Screenshot of the Open Solution option in the File menu in Visual Studio.

  2. The Visual Studio solution that you selected is now open in Solution Explorer.

    Screenshot of an open solution in 'Solution Explorer' in Visual Studio.

Next steps