Force HTTPS Over SSH for GitHub
A quick guide to authenticate with GitHub over HTTPS using the gh CLI and make Git always use HTTPS, even when remotes are set to SSH.
Authenticate with GitHub CLI
The easiest and most secure way to authenticate with GitHub over HTTPS is using the official GitHub CLI (gh). No need to manually create or manage personal access tokens.
Install it and run:
# Perform the initial login
gh auth login
# select `GitHub.com`
# then, select `HTTPS` and follow the instructions in the browser
# Now, update the `~/.gitconfig` to always use `gh` CLI for creds
gh auth setup-git
# Check the `~/.gitconfig`
cat ~/.gitconfigGitHub auth using gh CLI
When prompted, select GitHub.com, then HTTPS, and follow the browser-based login flow. Done — your credentials are now securely stored and Git will use them automatically for any HTTPS request.
You can verify your auth status anytime with:
# Check if your `gh` is working
gh auth status
# Check if `gh` is being invoked by `git`
git config --global --get credential.https://github.com.helper
# if must return something like:
>> !/path/to/bin/gh auth git-credentialcheck if it worked
Force HTTPS over SSH
Now that HTTPS auth is set up, you might still have repos with SSH remotes (git@github.com:...). Instead of updating each one manually, tell Git to always rewrite SSH URLs to HTTPS globally.
Add this to your ~/.gitconfig:
[url "https://github.com/"]
insteadOf = git@github.com:
insteadOf = ssh://git@github.com/
~/.gitconfig
Or run:
git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://github.com/".insteadOf ssh://git@github.com/
this will update the ~/.gitconfig
That's it. Every git clone, push, and pull to GitHub now uses HTTPS — no matter what the remote says.
References
- GitHub Docs — Managing remote repositories (switching from SSH to HTTPS)
https://docs.github.com/en/get-started/git-basics/managing-remote-repositories#switching-remote-urls-from-ssh-to-https