If you are an organization adopting Git with Team Foundation Server/Visual Studio Online, then you will definitely want to check out this article: https://www.visualstudio.com/en-us/docs/git/get-started
The original article references Visual Studio 2013, so if you are using Visual Studio 2015, you will want to check out this article instead for some updates: https://www.visualstudio.com/en-us/docs/git/share-your-code-in-git-vs
For a full overview of how to work with Git, you can go through all of the articles listed in the Overview: https://www.visualstudio.com/en-us/docs/git/overview
Once you have gone through the articles, you will want to make sure your environment is set up for using Git.
In order to do that, you will have to first set up your Source Control Plug-in to use Git by going into the Tools-->Options-->Source Control--Plug-in Selection:
Unfortunately, Microsoft Visual Studio leaves a lot to be desired when it comes to working with Git inside of Visual Studio.
Therefore, you will also probably want to at least install the GitExtensions Visual Studio extension as well: https://visualstudiogallery.msdn.microsoft.com/35c2f314-a6ab-479a-b4a3-cff99103d32f
In addition, it is frequently useful to have TortoiseGit installed as well to support working with Git from within Windows Explorer: https://tortoisegit.org/
Once you have one of these tools set up, you will want to connect to your Git repository and clone the repository to your local file system.
Now, you can create the solution or open an existing solution from within Visual Studio.
When you are working with Visual Studio solutions, however, there are typically a large number of files that you want to exclude from being checked into your Git source control repository, so you will need to add a .gitignore file using the following steps:
From the Team Explorer Home menu, click on the Settings button:
You will then be presented with a Settings dialog which will allow you to configure the Settings for Git. When you select the "Global Settings", you will be presented with options to configure your user credentials for your Git repository:
At the bottom of this screen, you will see the options to add a .gitignore file as well as a .gitattributes file.
You can click on the "Add" button to add a default .gitignore file to your solution so that the bin directory, packages and various other common directories and files will automatically be excluded from checking into your Git repository.
Once you have this set up, you will see the source control bindings in your Visual Studio Solution Explorer:
When you make changes to your code files, you will then be able to commit your changes to source control:
Just as with standard source control check-ins, you can enter a code comment before committing your code:
Then once you click on the "Commit All" button, this will ONLY commit the source code changes to your local file system! You will still have to "PUSH" or "SYNC" the source code changes to get them into your remote Git Repository!
After you commit your source code, Visual Studio will automatically provide you with a reminder notification that you have to do "Sync" of your source code to get it up into your remote Git Repository. You can click on the Sync hyperlink in the notification message to push your changes up to your Git repository:
Once you click on the "Push" hyperlink, your changes will be pushed up to your remote Git repository!
That is all there is to getting started with using Git with Visual Studio!!
The original article references Visual Studio 2013, so if you are using Visual Studio 2015, you will want to check out this article instead for some updates: https://www.visualstudio.com/en-us/docs/git/share-your-code-in-git-vs
For a full overview of how to work with Git, you can go through all of the articles listed in the Overview: https://www.visualstudio.com/en-us/docs/git/overview
Once you have gone through the articles, you will want to make sure your environment is set up for using Git.
In order to do that, you will have to first set up your Source Control Plug-in to use Git by going into the Tools-->Options-->Source Control--Plug-in Selection:
Unfortunately, Microsoft Visual Studio leaves a lot to be desired when it comes to working with Git inside of Visual Studio.
Therefore, you will also probably want to at least install the GitExtensions Visual Studio extension as well: https://visualstudiogallery.msdn.microsoft.com/35c2f314-a6ab-479a-b4a3-cff99103d32f
In addition, it is frequently useful to have TortoiseGit installed as well to support working with Git from within Windows Explorer: https://tortoisegit.org/
Once you have one of these tools set up, you will want to connect to your Git repository and clone the repository to your local file system.
Now, you can create the solution or open an existing solution from within Visual Studio.
When you are working with Visual Studio solutions, however, there are typically a large number of files that you want to exclude from being checked into your Git source control repository, so you will need to add a .gitignore file using the following steps:
From the Team Explorer Home menu, click on the Settings button:
You will then be presented with a Settings dialog which will allow you to configure the Settings for Git. When you select the "Global Settings", you will be presented with options to configure your user credentials for your Git repository:
Next up, you will have to configure your Git Repository settings. You can go back to the Git Settings screen and now select "Repository Settings":
At the bottom of this screen, you will see the options to add a .gitignore file as well as a .gitattributes file.
You can click on the "Add" button to add a default .gitignore file to your solution so that the bin directory, packages and various other common directories and files will automatically be excluded from checking into your Git repository.
Once you have this set up, you will see the source control bindings in your Visual Studio Solution Explorer:
When you make changes to your code files, you will then be able to commit your changes to source control:
Just as with standard source control check-ins, you can enter a code comment before committing your code:
Then once you click on the "Commit All" button, this will ONLY commit the source code changes to your local file system! You will still have to "PUSH" or "SYNC" the source code changes to get them into your remote Git Repository!
After you commit your source code, Visual Studio will automatically provide you with a reminder notification that you have to do "Sync" of your source code to get it up into your remote Git Repository. You can click on the Sync hyperlink in the notification message to push your changes up to your Git repository:
Once you click on the "Push" hyperlink, your changes will be pushed up to your remote Git repository!
That is all there is to getting started with using Git with Visual Studio!!
No comments:
Post a Comment