- Use
configure-git-credential-hellper.sh
script - You may have to install (Microsoft/Git-Credential-Manager-for-Windows)[https://github.com/Microsoft/Git-Credential-Manager-for-Windows/releases/latest]
Forked from RichardBronosky/Storing-git-Credentials.md
Created
October 17, 2021 06:30
-
-
Save reza/662d8c31b4a437095f14d14b3c835fb1 to your computer and use it in GitHub Desktop.
Storing git Credentials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
dos_path_to_linux(){ | |
sed -e 's?\\?/?g' -e' s?[cC]:?/mnt/c?' <<<"$1" | |
} | |
manager_path_from_git(){ | |
sed -e 's?/cmd/git.exe?/mingw64/libexec/git-core/git-credential-manager.exe?' <<<"$1" | |
} | |
escape_spaces(){ | |
sed -e 's? ?\\ ?g' <<<"$1" | |
} | |
find_where(){ | |
out="$(/mnt/c/Windows/System32/where.exe "$1" 2>/dev/null)" | |
status=$? | |
if ! $(exit $status); then | |
return $status | |
fi | |
sed -e 's/[[:space:]]*$//' <<<"$out" | |
} | |
info(){ | |
echo "$@" >/dev/stderr | |
} | |
get_manager_path(){ | |
winpath="$(find_where git-credential-manager.exe)" | |
status=$? | |
if $(exit $status); then | |
dos_path_to_linux "$winpath" | |
else | |
info "Did not find git-credential-manager.exe in DOS path." | |
gitpath="$(find_where git.exe)" | |
status=$? | |
if ! $(exit $status); then | |
echo "Did not find git.exe in DOS path." | |
echo "Install https://github.com/Microsoft/Git-Credential-Manager-for-Windows/releases/latest and try again." | |
exit 256 | |
fi | |
info "Found git at '$gitpath'" | |
manager_path_from_git "$(dos_path_to_linux "$gitpath")" | |
fi | |
} | |
path="$(get_manager_path)" | |
if ! [[ -x "$path" ]]; then | |
echo "Did not find executable at '$path'" | |
echo "Aborting" | |
exit 512 | |
fi | |
info "Found Credential Manager at '$path'" | |
info "Configuring git" | |
git config --global credential.helper "$(escape_spaces "$path")" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment