Using Git directly through VS2015 is one of the most common ways for you to incorporate it into your daily workflow to easily accomplish your most frequent tasks. However, at its roots, Git is a command-line tool, and in some cases, it can be advantageous to access Git in this manner.
Throughout the previous recipe Using Git for source control, you may have noticed that VS2015 was prompting you to install the 3rd-party command-line tools. In this recipe, we are going to do just that so that all of Git's functionality is available to you when Git is used with your projects.
This recipe will pick up directly from the previous one, but feel free to substitute your own Git-based project should you have one available. This recipe will assume you are using Visual Studio Community 2015 Update 2, but the important thing is for you to be using a version of VS2015 with Update 2 or newer applied.
To use Git on the command line, take the following steps:
Alternatively, you can select a local repository to work with from Team Explorer – Connect. Click on the menu Team | Manage Connections or use the hot key Ctrl + 0, C (that is, the number zero, followed by the letter C). Once that is open, right-click on the desired Git repository and select Open Command Prompt, as shown in the following screenshot:
git status
will indicate whether or not you have any outstanding files to commit, and indicate the branch you are on. The following listing is an example:c:usersjemardocumentsvisual studio 2015ProjectsCh8-Git-ConsoleApplication1>git status On branch master nothing to commit, working directory clean
git log
will show the commit history for the project you are working on. The following excerpt shows a portion of the history from our previous project:commit 5ac2388506970f3283c2a364c620f6537534f4ae Author: Jeff Martin <jemartin> Date: Sat Jun 25 13:07:16 2016 -0400 Adding new class commit bf162194b618b5a7c3166655be72d5c5dbe47c8f Author: Jeff Martin <jemartin> Date: Sat Jun 25 13:04:05 2016 -0400 Revert "Just project file" This reverts commit 2494dc217b7e752124b5a4bcf3b144720fea7248. commit 2494dc217b7e752124b5a4bcf3b144720fea7248 Author: Jeff Martin <jemartin> Date: Sat Jun 25 13:03:35 2016 -0400 Just project file
Installing the Git command-line tool allows VS2015 to work with the official project tools, and provide you with an additional option beyond the GUI based approach provided in VS2015. Since Git is a multiplatform tool, various tutorials and scripts will assume it is present, and this allows you to make use of them without being constrained by VS2015.
Not all of the Git commands are available through VS2015. There are a few that require you to use the command line, including stash
and reset
. For a complete list, go to https://www.visualstudio.com/en-us/docs/git/command-prompt.
While Microsoft recommends that you start the Git command prompt from within VS2015 as we have shown in this recipe, that isn't the only way. As part of the Git tools installation, you may also use the included Git Bash program. Git Bash is accessible through your Windows Start menu. This uses the familiar Bash shell environment to interface with your file system. The biggest immediate difference to using this via the approach in the recipe is that you will start in your Windows user's base directory rather than within your VS2015 project folder. Those of you familiar with Bash and its associated commands may prefer this method.
3.15.237.255