'git not working in visual studio code
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
Solution 1:[1]
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.
Solution 2:[2]
I had the same problem of Git not working in VSCode. After reading some of the earlier posts with their answers of deleting and reinstalling Git and Github, I discovered that I had the Atom GitHub package installed from prior experiments. I deleted Atom and restarted VSCode and it now works with the Git repo. That's all it took.
Solution 3:[3]
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.
Solution 4:[4]
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:
- Check VS Code Terminal Setting as explained on this link VS Code Documentation
- 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"
}
}
- Close Terminal, and then Run Terminal again, and check if Git command is recognized with
git --version. - Additional setting for Powershell to includes Git Command in
bootstrap-git.profile.ps1file 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.
Solution 5:[5]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | MartinDuo |
| Solution 3 | Paweł Raglis |
| Solution 4 | Yugo Gautomo |
| Solution 5 | Helder Antunes |
