Using Git with Visual Studio [closed]
Asked Answered
P

16

1464

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?

Perineum answered 3/2, 2009 at 14:46 Comment(9)
I just added the Git Source Control Provider for VS 2010, so it still works.Decry
Checkout this tutorial from VS team. 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. 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 tfs.visualstudio.comCowl
FYI visual studio update 3 now supports Git: blogs.msdn.com/b/visualstudioalm/archive/2014/07/02/…Joannajoanne
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!Oscillogram
Git is supported natively starting from Visual Studio 2013Virilism
@rustyx: it's true, but the "native" plugin is a steaming pile of unusability.Khalil
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?Angellaangelle
How is this opinion-based? "What technologies are available for using Git with Visual Studio?" is a clear question...Homograph
@Moira It was probably the opinion of the person who closed it. ;)Aureomycin
P
1072

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.

Posset answered 3/2, 2009 at 15:7 Comment(21)
Fantastic. This application is brilliant...i've been patiently using the command line and waiting for a tortoiseSVN equiv, but this is better.Gisborne
ted.dennison: According to this page (code.google.com/p/gitextensions) it is a VS 2005/2008 plugin.Accused
Vertis: TortoiseGit has been out for a while...Julius
It does work with VS2005Certify
To correct myself - the source is hosted on Github, the MSIs aren't.Erich
It seems to support VS2010 now.Marlonmarlow
I've installed git extensions, it works "by" visual studio, and not fully integrated. Is there a solution that enables check-in - check-out from the Solution Explorer ?Dipole
Dani, someone is working on a Git source control provider for VS that seems to provide a slightly deeper level of integration: gitscc.codeplex.comPosset
It's funny that the extension isn't source controled from Github...Colecolectomy
@Sung github.com/spdr870/gitextensionsAara
For me, a good Git front end would reduce the number of times I need to drop down to the command line to get stuff done. Been using Git Extensions for some time now (over a year) and its been more than 6 months since I've needed to drop down to the command line. I honestly cannot say that of any Git mac front end and I've tried just about all of them.Hesky
Are there any options for VS 2012?Ervin
@EarthEngine yesterday MS released a plugin for git! hanselman.com/blog/…Juliannajulianne
I wonder if this answer is getting all those votes because people really think this is an excellent answer or if people just love Git.Spotted
I upvoted it because it's the best answer right now, even though it's not a great one. Branch support is lacking, making it useless for certain projects of mine. However, for non-branched projects it's good to go...Catamount
This is an answer from 2009, starting with "In Jan 2013, Microsoft announced..." You had me baffled there, for a moment.Sharell
Any opinion for this?Tenpins
Git for VS doesn't fully support all git commands.Fighterbomber
Yea, That's right.Kirsti
What about unicode - can it be used? I know in older git there was no Unicode and UTF-8 was the only solution.Groundsheet
Why does the visual studio git tool do not support interface tag.. The interface is just include change, branch, sync, config.... NO tagFelty
F
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.

Faradmeter answered 3/2, 2009 at 14:51 Comment(13)
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.Devastation
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.Elfie
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.Sampan
@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.Faradmeter
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.Erinn
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...Rainproof
CXSharp link for good ignore templates seems to have died. Try this instead: github.com/github/gitignore/blob/master/VisualStudio.gitignoreThroughput
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 afterwardsEighteenth
@Rainproof - 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?Carapace
@Carapace 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.Rainproof
@Rainproof - 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...Carapace
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.Multiped
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 fileDiseased
P
93

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

Plio answered 31/5, 2010 at 22:16 Comment(3)
Is there any chance to get it working in 2005?Saffron
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.Bikales
I recommend seeing the review section in marketplace.visualstudio.com/… before decide to install it.Paralysis
I
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.

Intendancy answered 3/2, 2009 at 15:13 Comment(9)
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.Extranuclear
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.Mellie
@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 VSAit
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.Intendancy
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!Heaves
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.Hally
@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.Intendancy
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.Hydrogenolysis
@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.Swank
D
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.

Devastation answered 3/2, 2009 at 15:9 Comment(10)
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... :pJulius
Just curious, but why would you want it to ignore your project file?Supertax
You don't, you definitely should have your project file under version control.Devastation
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...Ballyhoo
@Benjol: It shouldn't be that painful. You just need to git rm <file> and echo <file> >>.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.Devastation
@Charles Bailey, see my adventures in this question: #1887549Ballyhoo
@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.Devastation
@Mike Brown: He is ignoring *.user files, which are user-specific settings.Extinctive
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.Licentiate
How do you know which files have changed without the VS integration?Diseased
J
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.

Julienne answered 30/1, 2013 at 23:10 Comment(1)
I recommend this one since it is microsoft official product. and it can install on VS 2012 express andDriedup
A
28

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

Alithia answered 26/5, 2009 at 1:21 Comment(2)
Yes, this is a good UI, but no, it does not integrate with Visual Studio.Hem
Git Source Control Provider adds TortoiseGit commands to the context menu in Visual Studio.Sakai
M
26

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

Mutz answered 30/1, 2013 at 17:32 Comment(3)
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!Reno
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?Janeljanela
I recommend seeing the review section in marketplace.visualstudio.com/… before decide to install it.Paralysis
E
19

Visual Studio 2013 natively supports Git.

See the official announcement.

Eicher answered 10/11, 2013 at 10:28 Comment(0)
H
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 ;-)

Hallam answered 9/12, 2013 at 16:20 Comment(1)
does GitExtensions work for you in vs 2015? the menu does not work for me github.com/gitextensions/gitextensions/issues/2815Wrapping
E
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.

Elexa answered 27/1, 2010 at 9:56 Comment(0)
R
15

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

Regale answered 30/5, 2011 at 11:0 Comment(0)
L
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

Lilliamlillian answered 30/8, 2011 at 18:44 Comment(1)
You can also just call git directly from the Package Manager Console, which is just a powershell commandline. Or... superuser.com/a/879561/135416Tidewater
B
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.

Biller answered 7/2, 2009 at 16:10 Comment(1)
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.Phonetics
E
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.

Eluviation answered 22/11, 2013 at 11:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.