Managing source code with GitHub
Git is a commonly used source code management system. GitHub is a company, website, and desktop application that makes it easier to manage Git.
I used GitHub to store solutions to all the practical exercises at the end of each chapter at the following URL:
https://github.com/markjprice/cs7dotnetcore.
Using Git with Visual Studio 2017
Visual Studio 2017 has built-in support for using Git with GitHub as well as Microsoft's own source code management system named Visual Studio Team Services.
Using the Team Explorer window
In Visual Studio 2017, navigate to View | Team Explorer to see the Team Explorer window:
Although it is a good idea to sign up with an online source code management system provider, you can clone a GitHub repository without signing up for an account.
Cloning a GitHub repository
In the Team Explorer window, expand Local Git Repositories, click on the Clone menu, and then enter the following URL of a Git repository to clone it: https://github.com/markjprice/cs7dotnetcore.git.
Enter a path for the cloned Git repository:
C:\Code\Repos\cs7dotnetcore
Click on the Clone button.
Wait for the Git repository to clone locally.
You will now have a local copy of the complete solutions to all the hands-on practice exercises for this book.
Managing a GitHub repository
Double-click on the cs7dotnetcore
repo to open a detail view.
You can click on the options in the Project section to view Pull Requests and Issues and other aspects of a repository.
You can double-click on an entry in the Solutions section to open it in the Solution Explorer.
Using Git with Visual Studio Code
Visual Studio Code has support for Git, but it will use your OS's Git installation, so you must install Git 2.0 or later first before you get these features. You can install Git from here: https://git-scm.com/download.
Note
If you like to use a graphical user interface, you can download GitHub Desktop here: https://desktop.github.com.
Configuring Git at the command line
Launch Terminal, and enter the following command to check your configuration:
git config --list
The output should include your username and e-mail address, because these will be used with every commit that you make:
...other congfiguration... user.name=Mark J. Price user.email=markjprice@gmail.com
If your user name and e-mail has not been set, to set your user name and email, enter the following commands, using your own name and e-mail, not mine:
git config --global user.name "Mark J. Price" git config --global user.email markjprice@gmail.com
You can check an individual configuration setting like this:
git config user.name
Managing Git with Visual Studio Code
Launch Visual Studio Code.
Navigate to View | Integrated Terminal or press Ctrl+ ` and enter the following commands:
cd Code mkdir Repos cd Repos git clone https://github.com/markjprice/cs7dotnetcore.git
It will take a minute to clone all the solutions for all the chapters to your local drive, as shown in the following screenshot:
It is best to open one project folder at a time because the cs7dotnetcore
repository does not include any dependencies, so you will need to restore them using the dotnet restore
command, or wait for Visual Studio Code to prompt you after opening a folder.
For more information about source code version control with Visual Studio Code, visit: https://code.visualstudio.com/Docs/editor/versioncontrol.