Why is git not working in Visual Studio Code?
Asked Answered
D

9

10

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

Dunfermline answered 9/8, 2017 at 23:14 Comment(0)
V
15

First, in the built-in terminal, type: git --version.

If that command does not work, download and install the latest version of Git. Else, in VS Code's extensions, 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.

Voltaire answered 10/7, 2018 at 16:7 Comment(0)
B
7

I had a somewhat similar issue - VS Code 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 what the OP did).

Inspired by @user9795515's answer, I resolved the problem with Git by restarting the Git feature in VSC:

  1. Go to Extensions
  2. In the search bar type @builtin
  3. Find Git and Git Base features and disable them
  4. Restart VS Code
  5. Re-enable both features
Bellda answered 15/2, 2022 at 9:53 Comment(0)
T
7

Uncheck the setting Require Git User Config in VS Code.

Example

Tonietonight answered 17/5, 2022 at 20:56 Comment(0)
S
5

After reading the other 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.

Sinaloa answered 8/12, 2017 at 22:0 Comment(1)
close and open VS Code helped me.Domela
M
0

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.

Mclyman answered 20/3, 2022 at 19:36 Comment(0)
H
0

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 I did that I restarted cmd and Visual Studio Code and it fixed the issue.

Hoarhound answered 29/8, 2022 at 1:32 Comment(0)
A
0

Had this same problem. Below is the solution that worked.

  1. Open Vscode
  2. Ctrl + Shift + P
  3. Type 'select default profile'
  4. Choose any terminal aside Powershell.

Don't know why powershell isn't working but changing to either CMD and Git bash works just fine.

Absolutism answered 28/3 at 3:24 Comment(0)
L
0

I have same problem and below step help me to fix my problem:

  1. unistall vs code and git then install them again.

  2. check the version of git

  3. go to settings Git:Enable and check it

  4. in your Terminal write:

    git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
    git commit -allow-empty -n -m "Initial commit"
    
Lyra answered 21/8 at 16:51 Comment(0)
D
-2

Try running git config --global safe.directory * in your terminal.

Deka answered 10/10, 2022 at 13:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.