Daily Archives

One Article

Visual Studio Tips

How to use git command line in Visual Studio

Posted by matteskolin on

Update: Visual Studio Community 2019 – Git Integration
Click link above for Visual Studio 2019 and later with new Git Menu (preview features enabled)
The git integration with Visual studio is great. It is able to find all the git repositories on your machine and show them all nicely in the team explorer.


However, when working with git, it is very useful to see the actual command line output. Using the GUI can obscure what is actually going on.

TFVC source control has the same problem, as when getting the latest changes, you don’t automatically see everything that’s happening, unless you take the time to open the Output window and navigate to the TFVC Output, where with the default settings you only see updated files in a list.

The command line is what really lets you see the details of what’s happening, as well as giving you the ability to try out all the commands and options, not all of which are available from within visual studio.

Below we can see all the details associated with a git pull from a remote repository. Insertions, deletions, and associated counts are neatly laid out and colored in green and red.

a git pull on the command line


How to Quickly Open the Command Prompt with the Project Directory
To quickly get started with the command prompt, it is very helpful to be able to open it directly in the path for the current project. To do this right click on the local git repository in VS and select open command prompt..

This opens a cmd.exe window opened to the project directory. I don’t like having to use tools outside the IDE unless absolutely necessary, as the context switching can slow productivity. I have started using the extension below which integrates a terminal windows.

Better Integration with a marketplace Extension (vsix)

https://marketplace.visualstudio.com/items?itemName=dos-cafe.WhackWhackTerminal

Update for Visual Studio 2019 – Seamless Git Integration

UPDATE: The above extension is no longer needed, as Visual Studio now integrates a terminal via the Developer Command Prompt. At the moment, I think I do prefer the powershell terminal, as the command highlighting and colors seem to work better.


Starting with Version 16.6, git functionality is accessible from within Visual Studio without installing an additional extension.

A new Git menu appears in the window title bar. I had some difficulty getting this menu to appear in my environment, but I eventually got it to work by toggling the “New git user experience” in the Preview Features of settings. For most users, the Git menu should appear by default by installing the new version of Visual Studio.

Enabling the new git experience


I don’t like the way that we no longer get pretty list of local repos right in the teams window like this..

This same list of repositories is now only available from the new Git Menu -> Local Repositories. The repositories that appear here are dependent on the path set in the Tools -> Options -> Source Control -> Git Global Settings -> Default Location

New List of Local Repositories with the new git menu

And Now, in order to open the command prompt with the working directory at the root of a git repo, a two step process is now required. First, open the repo by clicking it in the local repo menu above. Second, return to the Git menu, and select “Open in Command Prompt”

This is more difficult than it was before, but I will be on the lookout for improvements to this and will keep you all posted..