Learn to use Visual Studio, Visual Studio Online, Application Insights and Team Foundation Server to decrease rework, increase transparency into your application and increase the rate at which you can ship high quality software throughout the application lifecycle
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.
To use the Visual Studio client tools you'll need to install Visual Studio 2012, apply Visual Studio 2012 Update 2, and finally install Visual Studio Tools for Git. If you want to use Team Foundation Service, you can sign up for free.
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.
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.
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.
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: http://git-scm.com/docs.
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.
Create a local repository
Copy a remote repository to your dev machine
Fetch and pull changes from a remote repository
Get information about a repository
Commit your changes
Amend your last commit. Some typical cases:
Undo a committed change by applying the inverse of the commit. See rolling back changes with 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."
Branch and merge
Re-order history or combine commits. See Git Branching - Rebasing.
Push changes to a remote repository
I'd also strongly recommend that anyone more comfortable with Powershell than bash check out Keith Dahlby's Posh-git github.com/.../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:
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.
url = xxxx.visualstudio.com/.../Xxxx
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.