Skip to content

Instantly share code, notes, and snippets.

@sohang3112
Created October 11, 2024 02:49
Show Gist options
  • Save sohang3112/90c1035d3af5df20f04071bce429d68b to your computer and use it in GitHub Desktop.
Save sohang3112/90c1035d3af5df20f04071bce429d68b to your computer and use it in GitHub Desktop.
Bugfix: Github push (ssh) hanged

Problem

git push and git pull hanged (using SSH url).

Investigation

  • Enable tracing in git to check what's wrong:
$ GIT_TRACE=1 git push
trace: built-in: git push
trace: run_command: unset GIT_PREFIX; ssh [email protected] 'git-receive-pack '\''sohang3112/machine-learning-practice.git'\'''
trace: start_command: /usr/bin/ssh [email protected] 'git-receive-pack '\''username/repo.git'\'''
  • We're stuck at ssh connection to github, so let's check that seperately (enabling verbose mode for debugging):
$ ssh -vvv -t [email protected]
OpenSSH_9.6p1, OpenSSL 3.2.2 4 Jun 2024
debug1: Reading configuration data /home/sohang/.ssh/config
...
debug1: Connecting to github.com [64:ff9b::14cf:4952] port 22
  • SSH hanged while connecting to IPv6 address of Github, so let's try IPv4 instead:
$ ssh -o AddressFamily=inet -T [email protected]
PTY allocation request failed on channel 0
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

Solution

Using IPv4 for SSH connection worked (didn't hang)! Now let's set this option in SSH config so that it always uses IPv4 only for Github:

# add this in ~/.ssh/config file
Host github.com
  AddressFamily inet

Now git push and git pull work without hanging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment