SSH connection to GitHub failing? Blocked ports, restrictive networks, and VPN or firewall rules are common causes. You don't need to edit your repo's remote URL to get unblocked. You can temporarily route Git over HTTPS using the GitHub CLI.
Step 1: Authenticate with GitHub CLI
gh auth status --hostname github.com || gh auth login --hostname github.com --git-protocol https --web This checks whether you're already logged in. If not, it starts a browser-based login using HTTPS.
Step 2: Let Git use your GitHub CLI credentials
gh auth setup-git --hostname github.com This registers the GitHub CLI as a Git credential helper, so Git can authenticate over HTTPS without asking for a password or token.
Step 3: Rewrite SSH URLs to HTTPS for this session only
Instead of running git remote set-url, use environment variables so Git treats SSH URLs as HTTPS only in the current terminal session.
Bash / Zsh (macOS, Linux, Git Bash):
export GIT_CONFIG_COUNT=2 export GIT_CONFIG_KEY_0="url.https://github.com/.insteadOf" export GIT_CONFIG_VALUE_0="git@github.com:" export GIT_CONFIG_KEY_1="url.https://github.com/.insteadOf" export GIT_CONFIG_VALUE_1="ssh://git@github.com/" PowerShell (Windows):
$env:GIT_CONFIG_COUNT = "2" $env:GIT_CONFIG_KEY_0 = "url.https://github.com/.insteadOf" $env:GIT_CONFIG_VALUE_0 = "git@github.com:" $env:GIT_CONFIG_KEY_1 = "url.https://github.com/.insteadOf" $env:GIT_CONFIG_VALUE_1 = "ssh://git@github.com/" These variables require Git 2.31 or newer. Check your version with
git --version.
Step 4: Fetch your repository
cd <repo> git fetch origin Your remote still points to the SSH URL, but Git now connects over HTTPS behind the scenes.
Why use this approach?
- No need to change your remote URL
- Sidesteps common SSH connection problems
- Authentication is handled by GitHub CLI
- Your repository configuration stays untouched
💡 Pro tip
The URL rewrite from Step 3 lives in environment variables, so it disappears when you close the terminal. Re-run it in each new session, or open a new terminal when you want to go back to plain SSH.
To clear it manually:
unset GIT_CONFIG_COUNT GIT_CONFIG_KEY_0 GIT_CONFIG_VALUE_0 GIT_CONFIG_KEY_1 GIT_CONFIG_VALUE_1 Note that gh auth setup-git (Step 2) does write to your global Git config. It only adds a credential helper for github.com and is harmless to leave in place.
Sometimes a simple HTTPS fallback can save you a lot of debugging time. Have you run into SSH issues with GitHub? Share how you solved it in the comments! 👇




