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
Visual Studio dev tools & services make app development easy for any platform & language. Try our Mac & Windows code editor, IDE, or VSTS for free. How do I purchase Visual Studio Professional for Mac or Visual Studio Enterprise for Mac? Can I use my existing Visual Studio license on a Mac? Support Policies (1) What are the support policies for Visual Studio for Mac? Installation Help. Live Chat| English only 24×5, excluding holidays.
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:
Create a new Git repo at github.com:
Set Repo Name, description, and privacy. Do not initialize Repo. Set .gitignore and license to None:
The next page gives you an option to display and copy either the HTTPS or SSH address to the repo you have created:
You'll need the HTTPS address to point Visual Studio for Mac to this repo.
Publishing an existing project
If you have an existing project that is not already in version control, use the following steps to set it up in Git:
Select the Solution name from the Solution Pad in Visual Studio for Mac.
In the Menu bar, select Version Control > Publish in Version Control to display the Select Repository dialog:
If this menu item appears greyed out in the menu, make sure you have selected the Solution name.
Choose the Registered Repositories tab and press the Add button:
Enter the name of the repository as you would like it to display locally, and paste in the URL from step #3. Your Repository Configuration dialog should look similar to the following. Press OK:
It is also possible to use SSH to connect to Git.
To attempt to publish the app to Git, select the repository, and ensure that both Module Name and Message text fields are completed:
Click Okay, and then Publish from the alert dialog.
In the Git Credentials window, enter your GitHub username and password.
Note
If your account has two-factor authentication (2FA) enabled, you will need to create an Access Token, which is used in place of a password. If you have not created an access token, follow the steps in the Git Access Token documentation.
Enter the username and Personal Access Token, and press Okay:
After a few seconds, the Solution should be published with its initial commit. Confirm it has been published by browsing the Version Control menu item, which should now be populated with many options:
Once you start to make additional changes, select Push Changes to push the changes to the remote repository. This will allow all appropriate users to view it on github.com:
Publishing a new project
The new project dialog can be used to create a new project with a local git repository. To enable it, select the Use git for version control checkbox, as illustrated in the following screenshot. This will initialize your repo and add an optional .gitignore file:
Follow the steps below to push your new local repository to a new GitHub repository:
Note
If you have not already created a GitHub repository, refer to the Creating a remote repo on GitHub section.
Create your first commit by going to Version Control > Review Solution and Commit in the Menu Bar.
In the Status tab, choose Commit in the top left.
Write a commit message, for example 'First Commit', then click on Commit:
Next, in the Menu Bar go to Version Control > Manage Branches and Remotes.
Go to the Remote Sources tab, then click Add.
In the Remote Source window, add the details of your previously created GitHub repository and click OK:
Close the Git Repository Configuration window, then in the Menu Bar go to Version Control > Push Changes.
In the Push to Repository window click on the Push Changes button:
When prompted, enter your GitHub username and password.
Note
If your account has two-factor authentication (2FA) enabled, you will need to create an Access Token, which is used in place of a password. If you have not created an access token, follow the steps in the Git Access Token documentation.
Visual Studio for Mac will now push the changes to your remote GitHub repository:
Visual Studio Online For Mac
Check out an existing repository
It's likely that you'll have to work with a GitHub repo that exists only on the remote, not on your local machine. Visual Studio for Mac allows you to check this repo out quickly. Follow the steps below to clone it to your machine:
In the Menu bar, select Version Control > Checkout:
This displays the Connect to Repository tab:
On the GitHub page of the remote repository, press the Clone or Download button and copy the URL provided:
Replace all the text in the URL entry field in the Connect to Repository tab. This will populate most other fields in this tab for you, as illustrated in the image in step #2.
Enter the directory that you want to clone the repo into and press Checkout.
Note
You may experience issues if the repo is over 4 GB in size.
Troubleshooting
If you have issues with initializing your project with an empty remote repository, you can try the following steps:
- Go to your solution folder.
- Press Command + Shift + . to show the hidden files and folders.
- If there's a .git folder, delete it.
- If there's a gitignore file, delete it.
- Press Command + Shift + . to hide the files and folders.
- Open your solution in VS for Mac.
- On the solution Pad, select your solution node.
- Browse to the Version Control menu and choose Publish in Version Control.
- Follow the steps of the above tutorial starting from the step 6.
See also
Develop apps and games for iOS, Android,
and web using .NET
Code in C#, F#, Razor, HTML5, CSS, JavaScript, TypeScript, XAML, and XML
With the power of Roslyn, Visual Studio for Mac brings IntelliSense to your fingertips. IntelliSense describes APIs as you type and uses auto-completion to increase the speed and accuracy of how you write code.
Quick Info tool tips let you inspect API definitions, squiggly lines in the editor highlight issues, in real time as you type.
Use the Visual Studio debugger to quickly find and fix bugs across languages.
The Visual Studio for Mac debugger lets you step inside your code by setting Breakpoints, Step Over statements, Step Into and Out of functions, and inspect the current state of the code stack through powerful visualizations.
As your project grows, chances are, you’ll find yourself restructuring and refactoring code that you or someone else wrote earlier. That’s a whole lot easier when Visual Studio for Mac takes care of the heavy lifting for you.
Visual Studio For Mac Review
The Visual Studio for Mac editor supports powerful built-in refactoring options such as Extract Method and Rename, accessible via the Quick Actions menu.
Manage your code in Git or SVN repos hosted by any provider, including GitHub and Azure DevOps. Review diffs, stage files, and make commits from inside Visual Studio for Mac.
Choose the development environment that is right for you. With Visual Studio on both macOS and Windows, you can share your C# and F# projects seamlessly with your team using either OS.
FEATURES | Visual Studio 2019 for Mac | Visual Studio 2019 |
---|---|---|
Web and cloud development using C# | ||
ASP.NET Core and .NET Core | ||
Publish to Azure | ||
Azure Functions | ||
Azure Connected Services | ||
Docker container tools | ||
Desktop development | ||
WPF and Windows Forms | ||
UWP | ||
Mac Apps using Xamarin and C# | ||
Console apps with C# | ||
Desktop apps using C++ | ||
Mobile and gaming | ||
Mobile development with .NET using Xamarin and C# | ||
Game development using Unity and C# | ||
Mobile and game development using C++ | ||
Other workloads and tools | ||
Java | ||
Python | ||
SQL Server data tools | ||
Node.js | ||
Unit testing | ||
Version control with Git |
Create cross-platform apps targeting Android and iOS using Xamarin
Build, manage, and deploy cloud apps that scale to Azure
Create and debug cross platform games and 3D real time applications with Unity
Customers using Xamarin with Visual Studio for Mac
Launch a professional environment tailored to the Mac, free for most non-enterprise users