Use the Git command prompt to supplement Visual Studio

Use the Git command prompt to supplement Visual Studio

Rate This
  • Comments 6

By: Andy Lewis and Matthew Mitrik

In Visual Studio Tools for Git we aim to offer the fundamental features you need to develop an app in a Git version-controlled codebase. We explain how to perform these tasks in previous posts such as Create, Connect, and Publish using Visual Studio with Git and in our Git welcome portal content.

That said, there is a long tail of less-common tasks in software development work. If you can't yet do what you want to do in VS, you might be able to do it from the command prompt. Also, many developers find the command prompt to be a handy and efficient way to perform repetitive tasks, either manually or with a script.

Got the latest version of Visual Studio with Git? If not, click here.

Get set up to use the command prompt tools

Enable basic authentication for your TFS account

If your repo is hosted in Team Foundation Service (TFS), then you must enable basic authentication before you can use the command prompt to fetch, pull, push, clone, etc. You can set this up from your User Profile in TFS. Show me.

Tip: To make using the command prompt less tedious (for example, to avoid having to enter your credentials every time you push), you might want to also install Windows Credential Store for Git on your dev machine.

Get the command prompt tools

If you have not already installed some command-prompt tools, you can get some quickly from Visual Studio. (One way you can tell that you don't have the tools is if you try to enter a git command and get the 'git' is not recognized as an internal or external command... message.) Go to the Settings page and click Install 3rd-party tools. Show me.

Tip: The install process drops a Git Bash icon on your desktop. You can delete this icon; we don't believe this entry point leads to the best experience. And anyway, you can still get to it from Windows Start if for some reason you need it later.

Open the Git command prompt window

You can open the command prompt from the Actions menu on the Changes, Commits, and Branches pages. You can also open it from the Connect page: Right-click your local repo, and then click Open Command Prompt. Show me.

Work from the command prompt

We hope you find the following table to be a useful if not complete guide to some of the more common tasks. You can find more command-prompt reference information here:

Caution: If you are not an experienced Git user, use the command-prompt carefully. Make sure to research the command thoroughly before you use it.

Task Visual Studio Command Prompt

Create a local repository

Yes git-init

Copy a remote repository to your dev machine

Yes git-clone

Fetch and pull changes from a remote repository

Yes (some conflicts can be resolved only at command prompt) git-fetch, git-pull

Get information about a repository

You can if it is in a TFS team project (shown in bold text and with hover info in Team Explorer) git-remote

Commit your changes

Yes git-commit

Amend your last commit. Some typical cases:

No git-commit

Undo a committed change by applying the inverse of the commit. See rolling back changes with revert.

No git-revert

Undo committed changes by returning your local repo to a prior commit and de-referencing the later commit.  See Undoing Things, which warns, "...this is a dangerous command: any changes you made to that file are gone — you just copied another file over it. Don’t ever use this command unless you absolutely know that you don’t want the file."

No git-reset

Branch and merge

Yes (some conflicts can be resolved only at command prompt). (We plan to post more info on branches. For now, see our announcement post.) git-branch, git-merge

Re-order history or combine commits. See Git Branching - Rebasing.

No git-rebase

Push changes to a remote repository

Yes git-push
Leave a Comment
  • Please add 1 and 3 and type the answer here:
  • Post
  • I'd also strongly recommend that anyone more comfortable with Powershell than bash check out Keith Dahlby's Posh-git Not only do you get the full git command line in powershell, you get tab completion for all the popular git commands as well as your tags and branches and a convenient prompt that always tells you your current branch and the number of files deleted/modified/added. This tool alone is worth moving to GIT for managing source control on the command line.

  • When using command line tools after cloning with Visual Studio, I noticed that a basic "git fetch" wasn't working (it wasn't getting any remote changes).

    Looking at the .git/config file, the local branch is set up for remote tracking, but the configuration of the remote was slightly different than a new repository cloned directly on the command line.

    The repository configured by visual studio has "tagopt = --tags", which means that it is effecting doing "git fetch --tags", which is different from "git fetch".  As configured the command only gets tags, but that includes all tags (even those not referenced by a branch); I presume VS uses these types of tags for something.  

    The problem is it doesn't get commits I have been making from a different machine (a Mac, mostly using the command line, but also XCode). If I remove the tagopt line, then the command line behaves as expected (but I'm not sure if that breaks VS).

  • Just to follow up on my last comment, from the GIT documentation:

    " --tags

    This is a short-hand for giving "refs/tags/:refs/tags/" refspec from the command line, to ask all tags to be fetched and stored locally. Because this acts as an explicit refspec, the default refspecs (configured with the remote.$name.fetch variable) are overridden and not used. "

    This means that the configured refspec for the remote is ignore (due to the --tags option) and instead the tags refspec (above) is used. These are different. The normal refspec is for the remote tracking branch, and will include and tags in that branch (but not all tags).

    If you want both the remote tracking branch to work and all tags, then I think the config needs to have two fetch lines, i.e.

    [remote "origin"]

    url =

    fetch = +refs/heads/*:refs/remotes/origin/*

                     fetch = +refs/tags/:refs/tags/

    (If you don't need all tags, then just remove the tagopt = --tags altogether.)

  • Is there a way to point the plugin to a git executable if you already have it installed?

  • @smarts - Currently, we only support the developer command prompt.  In the future we hope to make this configurable so users can use other tools (i.e. powershell, bash, etc.)

  • 3rd party git tools is not an option on the Git Settings tab.

Page 1 of 1 (6 items)