git not working in visual studio code

Viewed 29223

I must have messed up something I have installed husky in my project. Then I ran precommit command. Now when I run git command, it is not working and asking me how do you want to open the file, so I removed husky using npm prune and then removed hooks folder from /.git of project directory but still didn't help. I am using windows 10

6 Answers

Do the following to solve this issue. In the inbuilt terminal type : git --version If that command does not work download and install latest version of git. Else to to extensions and in the search bar type: @builtin. This will list all the built-in extensions in vs-code categorized under different sections. In the 'Features' section look for Git extension. Check if it is disabled. Enable it and your version control should start working.

I had a somewhat similar issue - VSC stopped working with Git (for example: no change detection, problems with fetching from remotes), but I couldn't find what caused this issue (I didn't install Husky like @vihang-shah).

Inspired by @user9795515's answer, I resolved the problem with Git by restarting Git feature in VSC: go to Extensions -> in searchbar type @builtin -> find Git and Git Base features and disable them -> restart VSC -> reenable both features.

Try to check from Terminal, if Git command is recognized. Curently I'm using Powershell terminal. git --version this should be return like this git version 2.28.0.windows.1

If that doesn't work then try these steps:

  1. Check VS Code Terminal Setting as explained on this link VS Code Documentation
  2. Update setting.json. My settings would be like this.
"terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "args": ["-NoExit", "-ExecutionPolicy",  "Unrestricted", "-NoProfile", "-File", "C:\\Users\\LENOVO\\Documents\\WindowsPowerShell\\bootstrap-git.profile.ps1"],
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "Git Bash": {
            "source": "Git Bash"
        }
    }
  1. Close Terminal, and then Run Terminal again, and check if Git command is recognized with git --version.
  2. Additional setting for Powershell to includes Git Command in bootstrap-git.profile.ps1 file which is used in Point 2.
# Start a transcript
#
if (!(Test-Path "$Env:USERPROFILE\Documents\WindowsPowerShell\Transcripts"))
{
    if (!(Test-Path "$Env:USERPROFILE\Documents\WindowsPowerShell"))
    {
        $rc = New-Item -Path "$Env:USERPROFILE\Documents\WindowsPowerShell" -ItemType directory
    }
    $rc = New-Item -Path "$Env:USERPROFILE\Documents\WindowsPowerShell\Transcripts" -ItemType directory
}
$curdate = $(get-date -Format "yyyyMMddhhmmss")
Start-Transcript -Path "$Env:USERPROFILE\Documents\WindowsPowerShell\Transcripts\PowerShell_transcript.$curdate.txt"

# Alias Git
#
New-Alias -Name git -Value "$Env:ProgramFiles\Git\bin\git.exe"

Alternatively, if you're already installed Git, then try to using Git Bash Terminal in VS Code.

Uncheck the setting Require Git User Config in VS Code.

Example

It solves the problem to me.

I was facing the same problem however my git--version was working on cmd.

I have set up C:\Program Files\Git\bin and C:\Program Files\Git\cmd in PATH (windows->envirorment variable ->Path). Once done I restarted Cmd and visual studio and it fixed the issue.

Related