Dec 4, 2018

Using git (VS 2017 edition) with VSCode

Make sure the folder contains git.exe is in PATH in Windows.

For Visual Studio Community Edition git.exe is in:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\cmd

Add project to local git

cd "folder path to your repo"
git init
git add . # add everything
git commit -m "initial commit" 

Use source control tab in VS Code

If you don't see GIT in source control tab you can update your git.exe location.

  1. Go to settings in VSCode and search for "git path".
  2. Click "Edit in settings.json"
  3. Add path to user settings

"git.path": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\Git\\cmd\\git.exe"

Add to remote repository

C:\repo>git config credential.helper store

C:\repo>git push https://gitlab.com/username/repo.git --all
git: 'remote-https' is not a git command. See 'git --help'.
git-remote-https command is not reachable
C:\repo>git-remote-https
'git-remote-https' is not recognized as an internal or external command,
operable program or batch file.
Add git-remote-https.exe folder path to PATH.
C:\repo>SET PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw32\bin
Now it is reachable.
C:\repo> git-remote-https                                                                                                      
error: remote-curl: usage: git remote-curl  []
C:\repo>git push https://gitlab.com/username/repo.git
git: 'credential-cache' is not a git command. See 'git --help'.
Username for 'https://gitlab.com': username
Password for 'https://username@gitlab.com':
git: 'credential-cache' is not a git command. See 'git --help'.
Counting objects: 2653, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2324/2324), done.
Writing objects: 100% (2653/2653), 23.62 MiB | 170.00 KiB/s, done.
Total 2653 (delta 670), reused 0 (delta 0)
remote: Resolving deltas: 100% (670/670), done.
To https://gitlab.com/username/repo.git
 * [new branch]      master -> master
Error: 'credential-cache' is not a git command

For msysgit versions 1.8.1 and above
git config --global credential.helper wincred
Versions older than 1.8.1
git config --global credential.helper winstore
Git config file:
[credential]
 helper = winstore
Related errors:
Git http-push is not a git-command
Adding "..\mingw32\bin" folder also solves it.

VSCode commit

Now you should be able to commit and push to remote repository in VSCode. After any change go to source control tab and press "Stage Changes" button. Fill the message and press Commit (check icon) button.