mislav / hub

A command-line tool that makes git easier to use with GitHub.
https://hub.github.com/
MIT License
22.76k stars 2.2k forks source link

git clone hangs #2145

Closed mk0x9 closed 5 years ago

mk0x9 commented 5 years ago

When using git clone with github's user/repo format it expands to git://github.com/user/repo.git and git hangs indefinitely:

$ GIT_TRACE=1 git clone github/hub
11:36:26.288215 exec-cmd.c:139          trace: resolved executable path from Darwin stack: /Applications/Xcode.app/Contents/Developer/usr/bin/git
11:36:26.288683 exec-cmd.c:236          trace: resolved executable dir: /Applications/Xcode.app/Contents/Developer/usr/bin
11:36:26.288751 git.c:418               trace: built-in: git clone git://github.com/github/hub.git
Cloning into 'hub'...
^C

Is it possible to expand it to git@github.com:user/repo.git?

$ GIT_TRACE=1 git clone git@github.com:github/hub.git
11:36:49.269936 exec-cmd.c:139          trace: resolved executable path from Darwin stack: /Applications/Xcode.app/Contents/Developer/usr/bin/git
11:36:49.270427 exec-cmd.c:236          trace: resolved executable dir: /Applications/Xcode.app/Contents/Developer/usr/bin
11:36:49.270497 git.c:418               trace: built-in: git clone git@github.com:github/hub.git
Cloning into 'hub'...
11:36:49.281851 run-command.c:643       trace: run_command: unset GIT_DIR; ssh git@github.com 'git-upload-pack '\''github/hub.git'\'''
11:36:50.679794 run-command.c:643       trace: run_command: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 6366 on bln23020716.local' --check-self-contained-and-connected
remote: Enumerating objects: 33, done.
remote: Counting objects: 100% (33/33), done.
11:36:50.692600 exec-cmd.c:139          trace: resolved executable path from Darwin stack: /Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/git
remote: Compressing objects: 100% (29/29), done.
11:36:50.693297 exec-cmd.c:236          trace: resolved executable dir: /Applications/Xcode.app/Contents/Developer/usr/libexec/git-core
11:36:50.693899 git.c:418               trace: built-in: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 6366 on bln23020716.local' --check-self-contained-and-connected
remote: Total 17558 (delta 2), reused 15 (delta 1), pack-reused 17525
Receiving objects: 100% (17558/17558), 5.37 MiB | 9.00 MiB/s, done.
Resolving deltas: 100% (11318/11318), done.
11:36:51.371004 run-command.c:643       trace: run_command: git rev-list --objects --stdin --not --all --quiet '--progress=Checking connectivity'
11:36:51.373115 exec-cmd.c:139          trace: resolved executable path from Darwin stack: /Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/git
11:36:51.373528 exec-cmd.c:236          trace: resolved executable dir: /Applications/Xcode.app/Contents/Developer/usr/libexec/git-core
11:36:51.373870 git.c:418               trace: built-in: git rev-list --objects --stdin --not --all --quiet '--progress=Checking connectivity'
mislav commented 5 years ago

Is it possible to expand it to git@github.com:user/repo.git?

The SSH protocol for clone operations (i.e. the git@github.com: URL format) will automatically be used if:

Since neither of these is true for you and the github/hub repo, the git:// protocol will be used for cloning. This should work. If it doesn't work, this is still not a bug with hub, but with something in your git setup or your network preventing clones via git: protocol. Make sure that command git clone git://github.com/github/hub.git works for you locally (this command skips hub entirely).

When debugging, avoid using GIT_TRACE for now as hub has some bugs with it that were fixed in master branch but not yet released: https://github.com/github/hub/commit/0be001f76dbdbc3a2382c2f9b3928b7740953bdf. You can use HUB_VERBOSE instead.

Alternatively, you can skip both the SSH and git: protocol and have hub generate HTTPS URLs for you:

git config --global hub.protocol https

You will have to set up git credential caching.

mk0x9 commented 5 years ago

The SSH protocol for clone operations (i.e. the git@github.com: URL format) will automatically be used if:

  • user/repo is a private repository; or
  • you have write access to user/repo.

Why not use for repositories with read-only access? I don't get it. Still works with ssh protocol, and user could been granted later with write permissions.

Would it be possible to add setting for overriding hub.protocol with ssh procotol? Managing https credentials with git just only for github would be a little bit PITA, especially on linux & windows machines.

I really would prefer an option to force ssh protocol all the time. :/

mk0x9 commented 5 years ago

There something probably with the network, as the git is from the Xcode, and .gitconfig contains nothing special, just name/email and reference to global gitignore.

$ GIT_CURL_VERBOSE=1 GIT_TRACE=1 HUB_VERBOSE=1 command git clone git://github.com/github/hub.git
18:36:45.639567 exec-cmd.c:139          trace: resolved executable path from Darwin stack: /Applications/Xcode.app/Contents/Developer/usr/bin/git
18:36:45.640094 exec-cmd.c:236          trace: resolved executable dir: /Applications/Xcode.app/Contents/Developer/usr/bin
18:36:45.640171 git.c:418               trace: built-in: git clone git://github.com/github/hub.git
Cloning into 'hub'...
fatal: unable to connect to github.com:
github.com[0: 140.82.118.3]: errno=Operation timed out

I don't know, is it shitty ISP, corporate network or retrograde mercury.

dtrace.log

I can try to debug it, but currently I have no ideas how to tackle this issue.

mk0x9 commented 5 years ago

@mislav fixed it in gitconfig :)

[url "git@github.com:"]
    insteadOf = git://github.com/

Still, the additional possible value to hub.protocol would be nice to have.

mislav commented 5 years ago

@mk0x9 I'll consider adding an "always-ssh" config option when I'm reworking this whole part of the configuration next.

mk0x9 commented 5 years ago

Great, thanks!