简体   繁体   中英

Can I run Git commands in Visual Studio?

I am using Visual Studio Team Explorer with git integration for source control. It works pretty well but sometimes I need to run some more advanced git commands so I am going to file explorer and opening git bash. Can I run git commands inside Visual Studio?

Using Visual Studio 19.

You can use the Package Manager Console (in the bottom tab in VS) to run Git commands. see here

The Git integration in Visual Studio does not offer any terminal or ability to manually run Git commands. Using other means to obtain a terminal (ex: Package Manager Console as mentioned above) is a workaround for some Git commands.

You will run into some issues, though. For example, commands that present paged output (ex: Press key to continue) often do not work properly in the Package Manager Console. They may scroll all the way to the end of their results rather than breaking on page boundaries since they can't tell the size of the Package Manager Console tool window. There are some other little annoyances that you may encounter as well.

Git became the default revision control system with the update of Visual Studio 2019 to version 16.8 in November 2020. I'm aware of two main ways to start a git command prompt using 16.8 or newer:

  1. Right click the solution and choose Open in Terminal. This starts a PowerShell instance which docks (by default) at the bottom of Visual Studio and can be used to invoke system git.
  2. Git -> Open Repository in -> Command Prompt from the main menu (the top level Git menu is between the View and Project menus) opens a cmd.exe instance which also uses the system git installation.

Other methods of access include the options under Tools -> Command Line in the main menu. Starting a git command prompt through Team Explorer was removed Visual Studio 16.8. A functionality moved message is displayed instead.

As of 16.9.1, Visual Studio does not check that a system git installation is present (in C:\Program Files\Git by default). If no system git has been installed by the Git for Windows Visual Studio component or some other tool neither of the pathways described here will work. Thus, this part of Visual Studio's functionality can potentially be broken out of the box.

Visual Studio 2013 Update 1 through Visual Studio 2019 version 16.7 have a git client built into Team Explorer. To locate the feature, open a project that's controlled by Git (or just git init an existing project), and select View->Team Explorer from the menu. You'll see the " Connect " view, which looks a bit like this:

从团队资源管理器连接到 Git 存储库

You can read more about it here: https://devblogs.microsoft.com/devops/use-the-git-command-prompt-to-supplement-visual-studio/

Update: Visual Studio 2022

  • Open Visual Studio 2022
  • Find git options from top left 4
  • Click Open in command prompt

Basically it opens a cmd command prompt but it will work as git. Check git --version if you have already installed any version of git or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM