Skip to content

Instantly share code, notes, and snippets.

@CodeIter
Created April 9, 2022 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeIter/be215cfef4ec1af5e1a10c4563944869 to your computer and use it in GitHub Desktop.
Save CodeIter/be215cfef4ec1af5e1a10c4563944869 to your computer and use it in GitHub Desktop.
get git remote url as `https`. Whatever your remote Git repository settings are.

git-remote-http

get git remote url as https. Whatever your remote Git repository settings are.

use it :

  • for github.com repo :
    • git-remote-http.sh get first repo https url as ordered by git.
    • git-remote-http-all.sh get all repo https url as ordered by git.

License

MIT

#!/usr/bin/env bash
set -e
[ -z "${GITHOST}" ] && GITHOST="github.com"
[ -z "${GITBRANCH}" ] && GITBRANCH="origin"
git remote -v \
| grep "${GITBRANCH}" | grep fetch | while read -r line ; do \
cat <<< "${line}" \
| sed -re 's~\s+\(fetch\)$~~' \
-re 's~([^/ :]+/[^/ :]+)$~#\1~;s~^[^#]+#+~~' \
-re 's~(github\.com)~\1/~' \
-re '/^https?:\/\//!s~^~https://'"${GITHOST}"'/~'
done
#!/usr/bin/env bash
set -e
[ -z "${GITHOST}" ] && GITHOST="github.com"
[ -z "${GITBRANCH}" ] && GITBRANCH="origin"
git remote -v \
| grep "${GITBRANCH}" | grep fetch | head -n 1 \
| sed -re 's~\s+\(fetch\)$~~' \
-re 's~([^/ :]+/[^/ :]+)$~#\1~;s~^[^#]+#+~~' \
-re 's~(github\.com)~\1/~' \
-re '/^https?:\/\//!s~^~https://'"${GITHOST}"'/~'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment