- 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]
Last active
December 20, 2024 23:16
-
-
Save RichardBronosky/9ab50abb8698e02341629db21e5fa6bf 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