This Gist provides two focused commands:
git-https-to-sshconverts a GitHub HTTPS remote to SSH.git-ssh-to-httpsconverts a GitHub SSH remote to HTTPS.
Both commands default to origin, accept another remote name, show the exact proposed and rollback commands, support dry-run, require an exact confirmation by default, and verify the stored URL after changing it.
- Uses
git remote get-urlrather than parsing display-orientedgit remote -voutput. - Accepts only constrained remote names.
- Converts only recognized
github.comURL forms with one owner and repository component. - Does not use
eval. - Rejects credentials, query strings, fragments, extra path components, and non-GitHub hosts.
- Dry-run performs no Git configuration write.
- Interactive use requires typing
yes;--yesis available for deliberate automation. - Prints a copy-ready rollback command before mutation.
- Verifies the resulting remote and attempts restoration if verification fails.
These tools change only the selected repository remote. They do not alter submodule URLs, other remotes, global Git URL rewrite rules, credentials, SSH keys, or GitHub permissions.
- Bash 3.2 or newer
- Git
- A Git repository with the selected remote
These revision-free commands install the current remote scripts directly with elevated privileges.
HTTPS to SSH:
curl -fsSL https://gist.githubusercontent.com/lbussy/7f96a137d40e3074cacd2fc0732dabd0/raw/git_https_to_ssh.sh | sudo bash -c 'set -euo pipefail; install_tmp=$(mktemp); trap "rm -f -- \"$install_tmp\"" EXIT; cat > "$install_tmp"; test -s "$install_tmp"; bash -n "$install_tmp"; install -m 0755 "$install_tmp" /usr/local/bin/git-https-to-ssh'SSH to HTTPS:
curl -fsSL https://gist.githubusercontent.com/lbussy/7f96a137d40e3074cacd2fc0732dabd0/raw/git_ssh_to_https.sh | sudo bash -c 'set -euo pipefail; install_tmp=$(mktemp); trap "rm -f -- \"$install_tmp\"" EXIT; cat > "$install_tmp"; test -s "$install_tmp"; bash -n "$install_tmp"; install -m 0755 "$install_tmp" /usr/local/bin/git-ssh-to-https'These commands intentionally skip review and follow the current unpinned Gist revision. Anyone controlling the served content could install code with elevated privileges.
curl -fsSLO https://gist.githubusercontent.com/lbussy/7f96a137d40e3074cacd2fc0732dabd0/raw/git_https_to_ssh.sh
curl -fsSLO https://gist.githubusercontent.com/lbussy/7f96a137d40e3074cacd2fc0732dabd0/raw/git_ssh_to_https.sh
less git_https_to_ssh.sh
less git_ssh_to_https.sh
bash git_https_to_ssh.sh --install
bash git_ssh_to_https.sh --install
rm -f git_https_to_ssh.sh git_ssh_to_https.shThe URLs remain intentionally revision-free.
Preview HTTPS to SSH:
git-https-to-ssh --dry-runApply after confirmation:
git-https-to-sshConvert a different remote without prompting:
git-https-to-ssh --yes upstreamReverse the conversion:
git-ssh-to-httpsBoth converters accept -n for dry-run, -y for noninteractive confirmation, and an optional remote name.
HTTPS to SSH accepts:
https://github.com/OWNER/REPOSITORY
https://github.com/OWNER/REPOSITORY.git
SSH to HTTPS accepts:
git@github.com:OWNER/REPOSITORY
git@github.com:OWNER/REPOSITORY.git
ssh://git@github.com/OWNER/REPOSITORY
ssh://git@github.com/OWNER/REPOSITORY.git
The normalized outputs include .git.
- Changing transport can break authentication until SSH keys or HTTPS credentials are configured.
- A separately configured push URL is not changed by these tools; inspect
git remote -v. - Git worktrees share repository configuration, so the change affects every worktree using that repository.
- Existing Git processes may continue using a URL captured before the change.
- The scripts do not test GitHub connectivity or permissions; they only validate and update local configuration.
- GitHub Enterprise and other hosting providers are intentionally rejected.
--yesremoves the confirmation barrier and should be used carefully in automation.
MIT License. Use at your own risk.