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


Set up a Git repository in Visual Studio for Mac

Important

Visual Studio for Mac was retired on August 31, 2024 in accordance with Microsoft’s Modern Lifecycle Policy. While you can continue to work with Visual Studio for Mac, there are several other options for developers on Mac such as the preview version of the new C# Dev Kit extension for VS Code.

Learn more about support timelines and alternatives.

Git is a distributed version control system that allows teams to work on the same documents simultaneously. This means there is a single server that contains all the files, but whenever a repository is checked out from this central source, the entire repository is cloned locally to your machine.

There are many remote hosts that allow you to work with Git for version control, however the most common host is GitHub. The following example uses a GitHub host, but you can use any Git host for version control in Visual Studio for Mac.

If you wish to use GitHub, make sure that you have an account created and configured before following the steps in this article.

Creating a remote repo on GitHub

The following example uses a GitHub host, but you can use any Git host for version control in Visual Studio for Mac.

To set up a Git repository, execute the following steps:

  1. Create a new Git repo at github.com:

    Create new git repo

  2. Set Repo Name, description, and privacy. Do not initialize Repo. Set .gitignore and license to None:

    Set details of git repo

  3. The next page gives you an option to display and copy either the HTTPS or SSH address to the repo you have created:

    view and copy address

    You'll need the HTTPS address to point Visual Studio for Mac to this repo.

Clone an existing repository

Visual Studio for Mac makes it easy to clone a repository right from the IDE. You can work remotely with the Git provider of your choice, such as GitHub or Azure DevOps.

To clone a repository from GitHub:

  1. On the home page of the GitHub repo, click the Code button and choose the Open with Visual Studio option. Clone menu on GitHub, with cursor over the Open in Visual Studio link.
  2. When prompted in the browser to open Visual Studio, click the Open button.
  3. Visual Studio for Mac will launch with the Clone Git Repository dialog open with the URL of the GitHub repo.
  4. Choose a target folder path, then click Clone.

To clone a repo hosted on a different remote service:

  1. Copy the URL of the repo you want to clone.
  2. In the Visual Studio for Mac menu bar, select the Git > Clone Repository... menu.
  3. Paste the URL for the repo into the URL field of the Clone Git Repository dialog, choose a target folder path, then click Clone.

Clone dialog shown in Visual Studio for Mac, with a URL field set to the URL of the Git repo. A Target Folder path includes a file path. Cancel and Clone buttons are shown, with the Clone button set as the default button.

After clicking the Clone button, Visual Studio for Mac will clone the repository and open the first solution file (.sln) file found.