1463

As a long-time Visual SourceSafe user (and hater) I was discussing switching to SVN with a colleague; he suggested using Git instead. Since, apparently, it can be used as peer-to-peer without a central server (we are a 3-developer team).

I have not been able to find anything about tools that integrate Git with Visual Studio, though - does such a thing exist?

What are the technologies available for using Git with Visual Studio? And what do I need to know about how they differ before I begin?

PartTimeNerd
  • 305
  • 1
  • 2
  • 20
Herb Caudill
  • 50,043
  • 39
  • 124
  • 173
  • 4
    I just added the Git Source Control Provider for VS 2010, so it still works. – Wade73 Sep 19 '12 at 17:33
  • 3
    Checkout this [tutorial from VS team](http://blogs.msdn.com/b/visualstudioalm/archive/2013/01/30/getting-started-with-git-in-visual-studio-and-team-foundation-service.aspx). The next update; Update 2 for VS 2012 is coming any day now. You can also download the community technology preview (CTP) for VS2012 from [here](http://go.microsoft.com/fwlink/?LinkId=273878). Alternatively, if you are into CMMI, Agile, Scrum 1/2 etc. you can signup for free account (both public or private cloud instances) & invite members (teammates, clients) to ur project on web-based TFS http://tfs.visualstudio.com – Annie Apr 07 '13 at 20:25
  • FYI visual studio update 3 now supports Git: http://blogs.msdn.com/b/visualstudioalm/archive/2014/07/02/code-lens-for-git-improvements-in-visual-studio-2013-ultimate-update-3-rc.aspx – Maria Ines Parnisari Aug 14 '14 at 00:17
  • 3
    I have been using Visual Studio and git for two years now. I would say that the best solution to this problem is to just use a separate source control application like Atlassians SourceTree. It's free, easy to install, has a good GUI and is user friendly, you can browse multiple repositories(aka different projects) just like you would browse the web in Chrome, and, most importantly, support multiple source control systems. Give it a try! You wont be disappointed, I assure you! – Fazi Nov 05 '14 at 16:30
  • 2
    Git is supported [natively](https://msdn.microsoft.com/en-us/library/vstudio/hh850437(v=vs.120).aspx) starting from Visual Studio 2013 – rustyx Oct 20 '15 at 19:15
  • @rustyx: it's true, but the "native" plugin is a steaming pile of unusability. – Paolo Tedesco Apr 21 '16 at 12:04
  • 17
    I love how 1342 people have upvoted this question and some idiot comes and closes it anyway. Good going StackOverfolow.... What does it matter if doesn't fit SO's criteria if it's so many people find it so helpful. Isn't the point of this website is to be helpful? – thebunnyrules Jul 13 '17 at 03:09
  • 1
    _How_ is this opinion-based? "What technologies are available for using Git with Visual Studio?" is a clear question... – Salem Dec 10 '17 at 14:09
  • @Moira It was probably the opinion of the person who closed it. ;) – LeonidasFett Jan 31 '19 at 14:04

16 Answers16

1071

In Jan 2013, Microsoft announced that they are adding full Git support into all their ALM products. They have published a plugin for Visual Studio 2012 that adds Git source control integration.

Alternatively, there is a project called Git Extensions that includes add-ins for Visual Studio 2005, 2008, 2010 and 2012, as well as Windows Explorer integration. It's regularly updated and having used it on a couple of projects, I've found it very useful.

Another option is Git Source Control Provider.

Callum Watkins
  • 2,844
  • 4
  • 29
  • 49
Jon Rimmer
  • 12,064
  • 2
  • 19
  • 19
202

I use Git with Visual Studio for my port of Protocol Buffers to C#. I don't use the GUI - I just keep a command line open as well as Visual Studio.

For the most part it's fine - the only problem is when you want to rename a file. Both Git and Visual Studio would rather that they were the one to rename it. I think that renaming it in Visual Studio is the way to go though - just be careful what you do at the Git side afterwards. Although this has been a bit of a pain in the past, I've heard that it actually should be pretty seamless on the Git side, because it can notice that the contents will be mostly the same. (Not entirely the same, usually - you tend to rename a file when you're renaming the class, IME.)

But basically - yes, it works fine. I'm a Git newbie, but I can get it to do everything I need it to. Make sure you have a git ignore file for bin and obj, and *.user.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 35
    git should be fine with VS doing the renaming. For good rename tracking in git log you just have to be sure that you stage the 'remove' part of the change in the same commit as the 'add' part. git add -A makes this easy if your .gitignore is up to date. – CB Bailey Feb 03 '09 at 14:58
  • 40
    I'm a git newbie too, and to tell you the truth I *prefer* to use it from the command line. I'd be a bit scared to handle the git power to a GUI that tries to be "clever" and do some "magic" behind my back. – hasen Apr 03 '09 at 13:32
  • 1
    Thanks for the advice. I just moved to git (and github) and will never look back. My client uses perforce (ugh!). So my plan is to make one checkout from perforce, do my work with git, then check it back in. – Mark Beckwith Feb 26 '10 at 14:52
  • 7
    @CallMeLaNN: You're making a big assumption there, about newbies to Git having difficulty when using the command line. Look at hasan j's comment from April 2009. – Jon Skeet Jul 12 '10 at 16:10
  • I usually add *.user, *.suo, bin, obj, .* and _* to my ignore list... if there's one of the above I want added, I can still add it manually. – Tracker1 Mar 30 '11 at 00:17
  • I have the same workflow. I always have a commandline window open (NConsole with git-posh scripting) and switch back to that window when committing. I actually tried (forcing myself) to use GitExtensions and/or TortoiseGit, but I always found myself switching back to the commandline. In the Windows community, people tend to look negatively if you tell them to use the commandline... – Sardaukar Sep 09 '11 at 11:02
  • CXSharp link for good ignore templates seems to have died. Try this instead: https://github.com/github/gitignore/blob/master/VisualStudio.gitignore – MZB Sep 09 '13 at 22:42
  • for the rename woes, it can be a good idea to throw in an extra commit for the rename only. It should always be a self-contained change that doesn't change much otherwise. Commits are cheap with git anyway, and you could always squash afterwards – Martijn Jan 27 '14 at 21:15
  • @Sardaukar - When working command line did you also use any of the Visual Studio Git extensions just to give you a "hint" about file statuses and changes in the IDE, before doing the command line operations? Or did you just let 'git status' be your friend and show you what needed to be done? In other words, was there anything in the UI that you used to make decisions once you got to the command line? – Howiecamp Jul 09 '14 at 18:42
  • @Howiecamp For a current project I had to use a different version control system (the horror). I still find that with Git I use the commandline exclusively. I always have a commandline window open (yea for multiple monitors) and a simple git status tells me all I need. – Sardaukar Jul 10 '14 at 12:11
  • @Sardaukar - It is probably my lack of experience in this area that is behind my naïve questions like this. So can I assume that you don't rely on the Visual Studio IDE for visual indications of source control statuses at all? And that you get 100% of that feedback from the command line? It's just a change in my way of thinking that I am making. On the positive side of this, it seems like removing the issues associated with IDE project bindings to source control eliminates a source of complexity... – Howiecamp Jul 10 '14 at 15:35
  • Thanks for mentioning the .gitignore file...turns out mine already had bin obj and *.user files in it, but as a fellow git newbie it was very helpful to be reminded that that file exists and I need to be utilizing it. – levininja Oct 31 '14 at 00:37
  • Just a note that if you're using the VS Git integration you can get VS to create a very comprehensive .gitignore file for you in Settings > Repository Settings > Add ignore file – Caltor Jan 05 '17 at 22:42
93

Git Source Control Provider is new plug-in that integrates Git with Visual Studio.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
yysun
  • 1,026
  • 7
  • 2
  • Is there any chance to get it working in 2005? – Art Jun 01 '10 at 23:18
  • 3
    Well. TBH the graphical interface of this is exactly what I was looking for when I searched for a GUI for git within VS 2010. Thanks for posting this. The other answers are not what I need. They are poor in comparison to VisualSVN. – JDPeckham Mar 18 '12 at 16:19
  • 1
    I recommend seeing the review section in https://marketplace.visualstudio.com/items?itemName=yysun.GitSourceControlProvider#review-details before decide to install it. – QMaster Oct 14 '18 at 11:25
52

I've looked into this a bit at work (both with Subversion and Git). Visual Studio actually has a source control integration API to allow you to integrate third-party source control solutions into Visual Studio. However, most folks don't bother with it for a couple of reasons.

The first is that the API pretty much assumes you are using a locked-checkout workflow. There are a lot of hooks in it that are either way expensive to implement, or just flat out make no sense when you are using the more modern edit-merge workflow.

The second (which is related) is that when you are using the edit-merge workflow that both Subversion and Git encourage, you don't really need Visual Studio integration. The main killer thing about SourceSafe's integration with Visual Studio is that you (and the editor) can tell at a glance which files you own, which must be checked out before you can edit, and which you cannot check out even if you want to. Then it can help you do whatever revision-control voodoo you need to do when you want to edit a file. None of that is even part of a typical Git workflow.

When you are using Git (or SVN typically), your revision-control interactions all take place either before your development session, or after it (once you have everything working and tested). At that point it really isn't too much of a pain to use a different tool. You aren't constantly having to switch back and forth.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
T.E.D.
  • 44,016
  • 10
  • 73
  • 134
  • Exactly. My company uses SourceGear Vault, which does have VS integration. But since it also supports the edit-merge-commit workflow, I never ever (ever) actually use the VS integration. In fact, I think I uninstalled that bit. – Joel Mueller Feb 03 '09 at 19:35
  • 22
    Don't you guys ever move or rename files/directories? I started using VisualSVN a couple of months ago and I could never go back. – JohnOpincar Apr 05 '09 at 01:20
  • 10
    @TED To me this means that after a long development you have to remember the reasons for every file change until you check in. If I am working on something and see something that needs to be fixed in a unrelated area I like to check out, fix, and check in knowing that I can purge that change from my memory. I'd rather do this from within VS – Peter M Feb 24 '10 at 19:13
  • I suppose. I generally don't have that particular situation come up much. When I do, the responsible thing is to turn around and pull down that baseline into a fresh directory and build and test it, to ensure the change doesn't screw up devlopers who don't have my other unmerged changes available. That is generally best done with a second instance of VS, so you are *still* going outside your one VS instance as part of the process. – T.E.D. Feb 25 '10 at 13:53
  • 4
    The Git Extensions Visual Studio plugin doesn't try to shoehorn itself in to the old school locked-checkout source control API that Microsoft have provided. It is very well suited to an edit-merge workflow and basically just adds commit/push/pull and file history right inside the IDE. Having file history on the context menu is extremely useful! – Jacob Stanley Apr 07 '10 at 17:06
  • 3
    I disagree mainly because having to go out of visual studio to check in encourages longer times between check ins. Too many people already checkout at the start of the day and don't check in until the end (or worse days later). Integration with visual studio allows for you to constantly keep the source control in your workflow. – Chris McGrath Apr 22 '10 at 23:34
  • 1
    @Chris - Ahh, you are clearly a member of the "check in early and often" camp. You are entitiled to your opinion, of course. However, I'm a member of the "don't check it in unless it works" camp. Revision control systems are for controlling working software revisions. If I want disaster backups of works in progress, that's what IT's backups are for. But for you, yeah VS integration would be a lot more useful. – T.E.D. Apr 23 '10 at 12:40
  • 8
    Visual Studio source control integration as of VS2005 (VS2003?) doesn't particularly lean towards a checkout-checkin model. Look at AnkhSVN for example. I prefer VS integration, because then renames, etc. are smoother. – Roger Lipscombe Dec 21 '10 at 16:42
  • 1
    @T.E.D.: With DVCS's local branching I think "check in early and often" makes even more sense. You'll have your own revision history and you don't have to expose other people to it until it works. – Merlyn Morgan-Graham Mar 13 '12 at 06:12
38

I find that Git, working on whole trees as it does, benefits less from IDE integration than source control tools that are either file based or follow a checkout-edit-commit pattern. Of course there are instances when it can be nice to click on a button to do some history examination, but I don't miss that very much.

The real must-do is to get your .gitignore file full of the things that shouldn't be in a shared repository. Mine generally contain (amongst other stuff) the following:

*.vcproj.*.user
*.ncb
*.aps
*.suo

but this is heavily C++ biased with little or no use of any class wizard style functionality.

My usage pattern is something like the following.

  1. Code, code, code in Visual Studio.

  2. When happy (sensible intermediate point to commit code, switch to Git, stage changes and review diffs. If anything's obviously wrong switch back to Visual Studio and fix, otherwise commit.

Any merge, branch, rebase or other fancy SCM stuff is easy to do in Git from the command prompt. Visual Studio is normally fairly happy with things changing under it, although it can sometimes need to reload some projects if you've altered the project files significantly.

I find that the usefulness of Git outweighs any minor inconvenience of not having full IDE integration but it is, to some extent, a matter of taste.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CB Bailey
  • 755,051
  • 104
  • 632
  • 656
  • How about telling Git to ignore the bin/ and obj/ directories within a project too? Unless, of course, you want it to track your build cruft... :p – Chris Charabaruk Aug 28 '09 at 00:20
  • Just curious, but why would you want it to ignore your project file? – Michael Brown Oct 24 '09 at 18:12
  • 11
    You don't, you definitely should have your project file under version control. – CB Bailey Oct 25 '09 at 11:10
  • 1
    This is very important - recovering from forgetting to include something in .gitignore once you've started committing and branching is painful, to say the least... – Benjol Apr 09 '10 at 07:38
  • 3
    @Benjol: It shouldn't be that painful. You just need to `git rm ` and `echo >>.gitignore; git add .gitignore` on the tips of your active branches. Once you've committed the change once you can always cherry-pick the fix onto other branches. – CB Bailey Apr 09 '10 at 08:22
  • 1
    @Charles Bailey, see my adventures in this question: http://stackoverflow.com/questions/1887049/recovering-from-forgetting-to-gitignore – Benjol Apr 09 '10 at 08:35
  • @Benjol: I think your linked question isn't relevant to this question. Here we are talking about ignoring files that Visual Studio will automatically generate, whereas you were concerned with recovering files that you'd removed from a branch (and ignored) but still needed to reinstate in your working tree because they weren't automatically generated. – CB Bailey Apr 09 '10 at 09:18
  • 9
    @Mike Brown: He is ignoring *.user files, which are user-specific settings. – Srdjan Jovcic May 18 '10 at 16:52
  • 1
    I agree. I recently made the switch from Subversion to git. I have been using the command line instead of a VS plugin and this works just fine. I originally thought working without a VS plugin would be a pain, but that was a misconception I had because of my Subversion experience. – still_dreaming_1 Sep 29 '10 at 21:44
  • How do you know which files have changed without the VS integration? – Caltor Jan 06 '17 at 00:05
31

Microsoft announced Git for Visual studio 2012 (update 2) recently. I have not played around with it yet, but this video looks promising.

Here is a quick tutorial on how to use Git from Visual Studio 2012.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • I recommend this one since it is microsoft official product. and it can install on VS 2012 express and – Cheung Sep 10 '13 at 12:53
28

Also don't miss TortoiseGit... https://tortoisegit.org/

MrTux
  • 32,350
  • 30
  • 109
  • 146
tonyo
  • 309
  • 3
  • 2
26

There's a Visual Studio Tools for Git by Microsoft. It only supports Visual Studio 2012 (update 2) though.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sheng Jiang 蒋晟
  • 15,125
  • 2
  • 28
  • 46
  • for visual studio 2012, this is the best answer. It appears they put a lot of effort in the implementation, and in my experience it works as expected! – RoelF Feb 08 '13 at 16:30
  • 2
    I have not been able to figure out how to configure "Visual Studio Tools for Git" by Microsoft to use a private Github repo. Have you seen any documentation or tutorials on that? – golliher Feb 28 '13 at 22:33
  • I recommend seeing the review section in https://marketplace.visualstudio.com/items?itemName=TFSPowerToolsTeam.VisualStudioToolsforGit#review-details before decide to install it. – QMaster Oct 14 '18 at 11:25
19

Visual Studio 2013 natively supports Git.

See the official announcement.

Flexo
  • 87,323
  • 22
  • 191
  • 272
rhughes
  • 9,257
  • 11
  • 59
  • 87
18

The Git support done by Microsoft in Visual Studio is just good enough for basic work (commit/fetch/merge and push). My advice is just to avoid it...

I highly prefer GitExtensions (or in less proportion SourceTree). Because seeing the DAG is for me really important to understand how Git works. And you are a lot more aware of what the other contributors to your project have done!

In Visual Studio, you can't quickly see the diff between files or commit, nor (add to the index) and commit only part of modifications. Browse your history is not good either... All that ending in a painful experience!

And, for example, GitExtensions is bundled with interesting plugins: background fetch, GitFlow,... and now, continuous integration!

For the users of Visual Studio 2015, Git is taking shape if you install the GitHub extension. But an external tool is still better ;-)

Community
  • 1
  • 1
Philippe
  • 28,207
  • 6
  • 54
  • 78
  • does GitExtensions work for you in vs 2015? the menu does not work for me https://github.com/gitextensions/gitextensions/issues/2815 – raklos Sep 22 '16 at 13:31
15

The newest release of Git Extensions supports Visual Studio 2010 now (along with Visual Studio 2008 and Visual Studio 2005).

I found it to be fairly easy to use with Visual Studio 2008 and the interface seems to be the same in Visual Studio 2010.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
15

TortoiseGit has matured and I recommend it especially if you have used TortoiseSVN.

SurfRat
  • 926
  • 2
  • 8
  • 14
14

The simplest solution that actually works quite well is to add the TortoiseGit commands as external tools.

Solution to adding a Git (TortoiseGit) toolbar to Visual Studio

Community
  • 1
  • 1
DalSoft
  • 10,673
  • 3
  • 42
  • 55
  • 1
    You can also just call git directly from the Package Manager Console, which is just a powershell commandline. Or... http://superuser.com/a/879561/135416 – drzaus Feb 18 '15 at 17:21
10

As of 2013-02-11, the Microsoft Git plugin for Visual Studio 2012 should work with the Express version as well.

TTT
  • 22,611
  • 8
  • 63
  • 69
10

Currently there are 2 options for Git Source Control in Visual Studio (2010 and 12):

  1. Git Source Control Provider
  2. Microsoft Git Provider

I have tried both and have found 1st one to be more mature, and has more features. For instance it plays nicely with both tortoise git and git extensions, and even exposed their features.

Note: Whichever extension you use, make sure that you enable it from Tools -> Options -> Source control -> Plugin Selection for it to work.

Tarun
  • 2,808
  • 3
  • 22
  • 21
10

As mantioned by Jon Rimmer, you can use GitExtensions. GitExtensions does work in Visual Studio 2005 and Visual Studio 2008, it also does work in Visual Studio 2010 if you manually copy and config the .Addin file.

Henk
  • 247
  • 3
  • 3
  • good one. I wonder who is testing and approving the user interface...messages all over are very confusing...my only guess is that they rushed to put it out and see what/why the user complains. – ramnz Apr 24 '13 at 16:04