I've tried following these instructions: https://stackoverflow.com/a/40312117/21728 which basically do this:
sudo apt-get install libsecret-1-0 libsecret-1-dev
cd /usr/share/doc/git/contrib/credential/libsecret
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
But when I do any network operation, I get this error:
** (process:7902): CRITICAL **: could not connect to Secret Service: Cannot autolaunch D-Bus without X11 $DISPLAY
That's logical I guess as there is indeed no X11 display.
How to make Git credentials caching work on Ubuntu on Windows (WSL)?
TL;DR
I've created a script that does this for you. I use it with my Chef orchestration.
Locate or install git-credential-manager.exe
cmd.exe
and callwhere git-credential-manager.exe
cmd.exe
callwhere git.exe
C:\Program Files\Git\cmd\git.exe
C:\Program Files\Git\mingw64\libexec\git-core\git-credential-manager.exe
where
again to get the path.Convert the path from DOS to Linux
We need to:
C:\
with/mnt/c/
\
to/
\\
So...
"C:\Program Files\Git\mingw64\libexec\git-core\git-credential-manager.exe"
becomes..."/mnt/c/Program\\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe"
My script above has a function for doing just that
But, as @12345ieee has since commented, a
wslpath
utility has been added to WSL build 17046. It's worth checking out, but I don't have access to Windows at this time to verify. (Note that even though a usage statement is given in the release notes in my link, it seems that the command doesn't currently include a usage statement, -h, etc.)Configure git
bash
callgit config --global credential.helper "<converted/path>"
Using Windows 10 and "WSL", I created a ~/.gitconfig file, but had mistyped the [credential] section label as [credentials]. I tried running git credential fill and then feeding its output to git credential approve, which might have worked, but I suspect not since it said "usage: git credential [fill|approve|reject]". Finally, I simply ran:
and then did a git pull; when prompted for user and password I typed them as usual. After that, it remembered it. I found it had added the (correctly named) section to my ~/.gitconfig:
I edited that to provide a much longer timeout:
And it all seems to be working nicely now.
If you installed Git for Windows there is a windows integrated credential manager installed on your system.
You can run windows executables from WSL as found here.
To use it you can run the following command (assuming that your git for windows is installed on C:\Program Files\Git)