vscode: git fatal error: file is outside directory

  • VSCode Version: 1.46.0 ( a5d1cc28bb5da32ec67e86cc50f84c67cc690321, 2020-06-10T09:03:20.462Z )
  • OS Version: Windows_NT x64 10.0.18363

Steps to Reproduce:

  1. Click the “Initialize Repository” button on the source control panel.
  2. Add files to stage by clicking the plus sign on the “CHANGES” panel.
  3. Then the error occurred: pc

The Git log is here with some of my edits:

Looking for git in: D:\Program Files\Git\bin\git.exe
Using git 2.9.2.windows.1 from D:\Program Files\Git\bin\git.exe
> git rev-parse --show-toplevel
fatal: Not a git repository (or any of the parent directories): .git
> git rev-parse --show-toplevel
> git rev-parse --show-toplevel
fatal: Not a git repository (or any of the parent directories): .git
> git rev-parse --show-toplevel
> git rev-parse --show-toplevel
> git rev-parse --show-toplevel
fatal: Not a git repository (or any of the parent directories): .git
> git init
> git rev-parse --show-toplevel
> git rev-parse --git-dir
Open repository: c:\Users\JohnDoe\my-repo
> git fetch
> git status -z -u
fatal: No remote repository specified.  Please, specify either a URL or a
remote name from which new revisions should be fetched.
> git symbolic-ref --short HEAD
> git rev-parse master
fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
> git for-each-ref --format %(refname) %(objectname) --sort -committerdate
> git remote --verbose
> git config --get commit.template
> git check-ignore -v -z --stdin
> git add -A -- c:\Users\JohnDoe\my-repo\.gitignore c:\Users\JohnDoe\my-repo\some.files.a c:\Users\JohnDoe\my-repo\some.files.b
fatal: c:\Users\JohnDoe\my-repo\.gitignore: 'c:\Users\JohnDoe\my-repo\.gitignore' is outside repository

However, my Git works when using pure commands:

PS C:\JohnDoe\my-repo> git add *
warning: LF will be replaced by CRLF in .gitignore
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in some.files.a
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in some.files.b
The file will have its original line endings in your working directory.

PS C:\JohnDoe\my-repo> git rm --cached *
rm '.gitignore'
rm 'some.files.a'
rm 'some.files.b'

I don’t know if this issue is related to the closed issue #88890.

Does this issue occur when all extensions are disabled?: Yes

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 12
  • Comments: 21 (6 by maintainers)

Most upvoted comments

Same issue after update yesterday, and I resolve it update my git to 2.27

Thank you @wz71014q and @sozonome, I updated my Git to 2.27 and the issue is solved.

Same issue after upgrading to 1.46.0

  • 1 after upgrading to 1.46.0

I also face the same issue after VS Code updated to 1.46. I checked my Git version and it was version 2.8.x Then I update my Git to version 2.27 and I don’t found any problems anymore.

I think it occurs when someone using older version of Git Either update the Git version or wait for the next VS Code update