How to use Git credential store on WSL (Ubuntu on Windows)?

前端 未结 5 435
有刺的猬
有刺的猬 2021-01-30 08:03

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
         


        
5条回答
  •  花落未央
    2021-01-30 08:49

    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

    1. Open cmd.exe and call where git-credential-manager.exe
      • If it returns a path, GREAT. Move on to converting the path.
      • If not...
    2. In cmd.exe call where git.exe
      • If it does not return a path, the next step is to install the Credential Manager alone
      • If it does return a path, it will be something like:
      • C:\Program Files\Git\cmd\git.exe
      • Let's drop the everything after the next to last slash and change it like so:
      • C:\Program Files\Git\mingw64\libexec\git-core\git-credential-manager.exe
      • If that exists, GREAT. Move on to converting the path.
      • Otherwise...
    3. Install Credential Manager from Microsoft's git repo, and then use where again to get the path.

    Convert the path from DOS to Linux

    We need to:

    1. Replace the C:\ with /mnt/c/
    2. Flip the slashes from \ to /
    3. Escape spaces (and parenthesis if there are any) with double backslashes \\

    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

    dos_path_to_linux(){
        sed -e 's?\\?/?g' -e' s?[cC]:?/mnt/c?' <<<"$1"
    }
    

    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

    1. In bash call git config --global credential.helper ""

提交回复
热议问题