ChatGPT解决这个技术问题 Extra ChatGPT

Using Git with Visual Studio [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 8 years ago. Improve this question

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?

I just added the Git Source Control Provider for VS 2010, so it still works.
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.com
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!
Git is supported natively starting from Visual Studio 2013
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?

C
Callum Watkins

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.


ted.dennison: According to this page (code.google.com/p/gitextensions) it is a VS 2005/2008 plugin.
To correct myself - the source is hosted on Github, the MSIs aren't.
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 ?
Dani, someone is working on a Git source control provider for VS that seems to provide a slightly deeper level of integration: gitscc.codeplex.com
Are there any options for VS 2012?
J
Jon Skeet

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.


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.
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.
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.
@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.
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.
P
Peter Mortensen

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


Is there any chance to get it working in 2005?
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.
I recommend seeing the review section in marketplace.visualstudio.com/… before decide to install it.
P
Peter Mortensen

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.


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.
@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
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!
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.
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.
P
Peter Mortensen

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.

Code, code, code in Visual Studio. 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.


You don't, you definitely should have your project file under version control.
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: 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.
@Charles Bailey, see my adventures in this question: stackoverflow.com/questions/1887049/…
@Mike Brown: He is ignoring *.user files, which are user-specific settings.
P
Peter Mortensen

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.


I recommend this one since it is microsoft official product. and it can install on VS 2012 express and
M
MrTux

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


Yes, this is a good UI, but no, it does not integrate with Visual Studio.
Git Source Control Provider adds TortoiseGit commands to the context menu in Visual Studio.
P
Peter Mortensen

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


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!
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?
I recommend seeing the review section in marketplace.visualstudio.com/… before decide to install it.
F
Flexo

Visual Studio 2013 natively supports Git.

See the official announcement.


C
Community

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 ;-)


does GitExtensions work for you in vs 2015? the menu does not work for me github.com/gitextensions/gitextensions/issues/2815
S
SurfRat

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


P
Peter Mortensen

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.


C
Community

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


You can also just call git directly from the Package Manager Console, which is just a powershell commandline. Or... superuser.com/a/879561/135416
H
Henk

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.


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.
T
Tarun

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

Git Source Control Provider 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.