@kyanny's blog

My thoughts, my life. Views/opinions are my own.

Git: HTTPS プロトコルで git clone/pull/push する際の HTTP デバッグログを見る

GIT_TRACE=1 以外にも色々な環境変数が指定できる。

HTTP 通信のログを見るには GIT_CURL_VERBOSE=1 を指定する。

debugging - How can I debug git/git-shell related problems? - Stack Overflow

GIT_CURL_VERBOSE=1 GIT_TRACE=1 git clone https://github.com/kyanny/hello

macOS 11.5.2 上の git 2.32.0 では以下のような出力になる。

$ GIT_CURL_VERBOSE=1 GIT_TRACE=1 git clone https://github.com/kyanny/hello
20:37:11.800261 git.c:455               trace: built-in: git clone https://github.com/kyanny/hello
Cloning into 'hello'...
20:37:11.811327 run-command.c:667       trace: run_command: git remote-https origin https://github.com/kyanny/hello
20:37:11.816890 git.c:743               trace: exec: git-remote-https origin https://github.com/kyanny/hello
20:37:11.817559 run-command.c:667       trace: run_command: git-remote-https origin https://github.com/kyanny/hello
20:37:11.827675 http.c:756              == Info: Couldn't find host github.com in the .netrc file; using defaults
20:37:11.883106 http.c:756              == Info:   Trying 13.114.40.48...
20:37:11.883150 http.c:756              == Info: TCP_NODELAY set
20:37:11.892599 http.c:756              == Info: Connected to github.com (13.114.40.48) port 443 (#0)
20:37:11.892742 http.c:756              == Info: ALPN, offering h2
20:37:11.892768 http.c:756              == Info: ALPN, offering http/1.1
20:37:11.898710 http.c:756              == Info: successfully set certificate verify locations:
20:37:11.898733 http.c:756              == Info:   CAfile: /etc/ssl/cert.pem
  CApath: none
20:37:11.898843 http.c:756              == Info: TLSv1.2 (OUT), TLS handshake, Client hello (1):
20:37:11.907147 http.c:756              == Info: TLSv1.2 (IN), TLS handshake, Server hello (2):
20:37:11.907232 http.c:756              == Info: TLSv1.2 (IN), TLS handshake, Certificate (11):
20:37:11.908281 http.c:756              == Info: TLSv1.2 (IN), TLS handshake, Server key exchange (12):
20:37:11.908673 http.c:756              == Info: TLSv1.2 (IN), TLS handshake, Server finished (14):
20:37:11.908912 http.c:756              == Info: TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
20:37:11.908923 http.c:756              == Info: TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
20:37:11.908955 http.c:756              == Info: TLSv1.2 (OUT), TLS handshake, Finished (20):
20:37:11.918571 http.c:756              == Info: TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
20:37:11.918751 http.c:756              == Info: TLSv1.2 (IN), TLS handshake, Finished (20):
20:37:11.918832 http.c:756              == Info: SSL connection using TLSv1.2 / ECDHE-ECDSA-AES128-GCM-SHA256
20:37:11.918850 http.c:756              == Info: ALPN, server accepted to use h2
20:37:11.918860 http.c:756              == Info: Server certificate:
20:37:11.918882 http.c:756              == Info:  subject: C=US; ST=California; L=San Francisco; O=GitHub, Inc.; CN=github.com
20:37:11.918892 http.c:756              == Info:  start date: Mar 25 00:00:00 2021 GMT
20:37:11.918899 http.c:756              == Info:  expire date: Mar 30 23:59:59 2022 GMT
20:37:11.918918 http.c:756              == Info:  subjectAltName: host "github.com" matched cert's "github.com"
20:37:11.918932 http.c:756              == Info:  issuer: C=US; O=DigiCert, Inc.; CN=DigiCert High Assurance TLS Hybrid ECC SHA256 2020 CA1
20:37:11.918940 http.c:756              == Info:  SSL certificate verify ok.
20:37:11.918966 http.c:756              == Info: Using HTTP2, server supports multi-use
20:37:11.918999 http.c:756              == Info: Connection state changed (HTTP/2 confirmed)
20:37:11.919007 http.c:756              == Info: Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
20:37:11.919098 http.c:756              == Info: Using Stream ID: 1 (easy handle 0x7fa6b002c400)
20:37:11.919131 http.c:703              => Send header, 0000000225 bytes (0x000000e1)
20:37:11.919142 http.c:715              => Send header: GET /kyanny/hello/info/refs?service=git-upload-pack HTTP/2
20:37:11.919148 http.c:715              => Send header: Host: github.com
20:37:11.919154 http.c:715              => Send header: User-Agent: git/2.32.0
20:37:11.919160 http.c:715              => Send header: Accept: */*
20:37:11.919166 http.c:715              => Send header: Accept-Encoding: deflate, gzip
20:37:11.919172 http.c:715              => Send header: Accept-Language: ja-JP, *;q=0.9
20:37:11.919191 http.c:715              => Send header: Pragma: no-cache
20:37:11.924139 http.c:715              => Send header: Git-Protocol: version=2
20:37:11.924203 http.c:715              => Send header:
20:37:11.927870 http.c:756              == Info: Connection state changed (MAX_CONCURRENT_STREAMS == 100)!
20:37:12.120119 http.c:703              <= Recv header, 0000000013 bytes (0x0000000d)
20:37:12.120162 http.c:715              <= Recv header: HTTP/2 200
20:37:12.120171 http.c:703              <= Recv header, 0000000026 bytes (0x0000001a)
20:37:12.120207 http.c:715              <= Recv header: server: GitHub Babel 2.0
20:37:12.120215 http.c:703              <= Recv header, 0000000059 bytes (0x0000003b)
20:37:12.120221 http.c:715              <= Recv header: content-type: application/x-git-upload-pack-advertisement
20:37:12.120257 http.c:703              <= Recv header, 0000000054 bytes (0x00000036)
20:37:12.120263 http.c:715              <= Recv header: content-security-policy: default-src 'none'; sandbox
20:37:12.120270 http.c:703              <= Recv header, 0000000040 bytes (0x00000028)
20:37:12.120278 http.c:715              <= Recv header: expires: Fri, 01 Jan 1980 00:00:00 GMT
20:37:12.120310 http.c:703              <= Recv header, 0000000018 bytes (0x00000012)
20:37:12.120347 http.c:715              <= Recv header: pragma: no-cache
20:37:12.120388 http.c:703              <= Recv header, 0000000053 bytes (0x00000035)
20:37:12.120434 http.c:715              <= Recv header: cache-control: no-cache, max-age=0, must-revalidate
20:37:12.120450 http.c:703              <= Recv header, 0000000023 bytes (0x00000017)
20:37:12.120462 http.c:715              <= Recv header: vary: Accept-Encoding
20:37:12.120473 http.c:703              <= Recv header, 0000000023 bytes (0x00000017)
20:37:12.120483 http.c:715              <= Recv header: x-frame-options: DENY
20:37:12.120496 http.c:703              <= Recv header, 0000000057 bytes (0x00000039)
20:37:12.120503 http.c:715              <= Recv header: x-github-request-id: E57F:0758:10C121B:13B9030:6130B767
20:37:12.120511 http.c:703              <= Recv header, 0000000002 bytes (0x00000002)
20:37:12.120517 http.c:715              <= Recv header:
20:37:12.123002 http.c:756              == Info: Connection #0 to host github.com left intact
20:37:12.123311 http.c:756              == Info: Couldn't find host github.com in the .netrc file; using defaults
20:37:12.123334 http.c:756              == Info: Found bundle for host github.com: 0x7fa69fd046b0 [can multiplex]
20:37:12.123350 http.c:756              == Info: Re-using existing connection! (#0) with host github.com
20:37:12.123359 http.c:756              == Info: Connected to github.com (13.114.40.48) port 443 (#0)
20:37:12.123378 http.c:756              == Info: Using Stream ID: 3 (easy handle 0x7fa6b002c400)
20:37:12.123410 http.c:703              => Send header, 0000000264 bytes (0x00000108)
20:37:12.123421 http.c:715              => Send header: POST /kyanny/hello/git-upload-pack HTTP/2
20:37:12.123460 http.c:715              => Send header: Host: github.com
20:37:12.123468 http.c:715              => Send header: User-Agent: git/2.32.0
20:37:12.123474 http.c:715              => Send header: Accept-Encoding: deflate, gzip
20:37:12.123483 http.c:715              => Send header: Content-Type: application/x-git-upload-pack-request
20:37:12.123492 http.c:715              => Send header: Accept: application/x-git-upload-pack-result
20:37:12.123511 http.c:715              => Send header: Git-Protocol: version=2
20:37:12.123581 http.c:715              => Send header: Content-Length: 164
20:37:12.123596 http.c:715              => Send header:
20:37:12.123634 http.c:756              == Info: We are completely uploaded and fine
20:37:12.315219 http.c:703              <= Recv header, 0000000013 bytes (0x0000000d)
20:37:12.315310 http.c:715              <= Recv header: HTTP/2 200
20:37:12.315328 http.c:703              <= Recv header, 0000000026 bytes (0x0000001a)
20:37:12.315340 http.c:715              <= Recv header: server: GitHub Babel 2.0
20:37:12.315353 http.c:703              <= Recv header, 0000000052 bytes (0x00000034)
20:37:12.315364 http.c:715              <= Recv header: content-type: application/x-git-upload-pack-result
20:37:12.315375 http.c:703              <= Recv header, 0000000054 bytes (0x00000036)
20:37:12.315387 http.c:715              <= Recv header: content-security-policy: default-src 'none'; sandbox
20:37:12.315398 http.c:703              <= Recv header, 0000000040 bytes (0x00000028)
20:37:12.315408 http.c:715              <= Recv header: expires: Fri, 01 Jan 1980 00:00:00 GMT
20:37:12.315422 http.c:703              <= Recv header, 0000000018 bytes (0x00000012)
20:37:12.315434 http.c:715              <= Recv header: pragma: no-cache
20:37:12.315448 http.c:703              <= Recv header, 0000000053 bytes (0x00000035)
20:37:12.315461 http.c:715              <= Recv header: cache-control: no-cache, max-age=0, must-revalidate
20:37:12.315476 http.c:703              <= Recv header, 0000000023 bytes (0x00000017)
20:37:12.315487 http.c:715              <= Recv header: vary: Accept-Encoding
20:37:12.315500 http.c:703              <= Recv header, 0000000023 bytes (0x00000017)
20:37:12.315512 http.c:715              <= Recv header: x-frame-options: DENY
20:37:12.315524 http.c:703              <= Recv header, 0000000057 bytes (0x00000039)
20:37:12.315537 http.c:715              <= Recv header: x-github-request-id: E57F:0758:10C1225:13B9041:6130B767
20:37:12.315549 http.c:703              <= Recv header, 0000000002 bytes (0x00000002)
20:37:12.315561 http.c:715              <= Recv header:
20:37:12.317253 http.c:756              == Info: Connection #0 to host github.com left intact
20:37:12.320097 http.c:756              == Info: Couldn't find host github.com in the .netrc file; using defaults
20:37:12.320124 http.c:756              == Info: Found bundle for host github.com: 0x7fa69fd046b0 [can multiplex]
20:37:12.320146 http.c:756              == Info: Re-using existing connection! (#0) with host github.com
20:37:12.320161 http.c:756              == Info: Connected to github.com (13.114.40.48) port 443 (#0)
20:37:12.320187 http.c:756              == Info: Using Stream ID: 5 (easy handle 0x7fa6b002c400)
20:37:12.320242 http.c:703              => Send header, 0000000264 bytes (0x00000108)
20:37:12.320254 http.c:715              => Send header: POST /kyanny/hello/git-upload-pack HTTP/2
20:37:12.320260 http.c:715              => Send header: Host: github.com
20:37:12.320266 http.c:715              => Send header: User-Agent: git/2.32.0
20:37:12.320272 http.c:715              => Send header: Accept-Encoding: deflate, gzip
20:37:12.320278 http.c:715              => Send header: Content-Type: application/x-git-upload-pack-request
20:37:12.320284 http.c:715              => Send header: Accept: application/x-git-upload-pack-result
20:37:12.320291 http.c:715              => Send header: Git-Protocol: version=2
20:37:12.320296 http.c:715              => Send header: Content-Length: 252
20:37:12.320302 http.c:715              => Send header:
20:37:12.320333 http.c:756              == Info: We are completely uploaded and fine
20:37:12.514738 http.c:703              <= Recv header, 0000000013 bytes (0x0000000d)
20:37:12.514809 http.c:715              <= Recv header: HTTP/2 200
20:37:12.514824 http.c:703              <= Recv header, 0000000026 bytes (0x0000001a)
20:37:12.514835 http.c:715              <= Recv header: server: GitHub Babel 2.0
20:37:12.514845 http.c:703              <= Recv header, 0000000052 bytes (0x00000034)
20:37:12.514854 http.c:715              <= Recv header: content-type: application/x-git-upload-pack-result
20:37:12.514864 http.c:703              <= Recv header, 0000000054 bytes (0x00000036)
20:37:12.514874 http.c:715              <= Recv header: content-security-policy: default-src 'none'; sandbox
20:37:12.514885 http.c:703              <= Recv header, 0000000040 bytes (0x00000028)
20:37:12.514900 http.c:715              <= Recv header: expires: Fri, 01 Jan 1980 00:00:00 GMT
20:37:12.514913 http.c:703              <= Recv header, 0000000018 bytes (0x00000012)
20:37:12.514927 http.c:715              <= Recv header: pragma: no-cache
20:37:12.514943 http.c:703              <= Recv header, 0000000053 bytes (0x00000035)
20:37:12.514957 http.c:715              <= Recv header: cache-control: no-cache, max-age=0, must-revalidate
20:37:12.514970 http.c:703              <= Recv header, 0000000023 bytes (0x00000017)
20:37:12.514987 http.c:715              <= Recv header: vary: Accept-Encoding
20:37:12.515004 http.c:703              <= Recv header, 0000000023 bytes (0x00000017)
20:37:12.515019 http.c:715              <= Recv header: x-frame-options: DENY
20:37:12.515035 http.c:703              <= Recv header, 0000000057 bytes (0x00000039)
20:37:12.515051 http.c:715              <= Recv header: x-github-request-id: E57F:0758:10C1236:13B9057:6130B768
20:37:12.515069 http.c:703              <= Recv header, 0000000002 bytes (0x00000002)
20:37:12.515105 http.c:715              <= Recv header:
20:37:12.518858 run-command.c:667       trace: run_command: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 7182 on KensukenoMacBook-Pro.local' --check-self-contained-and-connected
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
20:37:12.523223 http.c:756              == Info: Connection #0 to host github.com left intact
20:37:12.525878 git.c:455               trace: built-in: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 7182 on KensukenoMacBook-Pro.local' --check-self-contained-and-connected
Receiving objects: 100% (6/6), done.
* Closing connection 0
20:37:12.534118 run-command.c:667       trace: run_command: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity'
20:37:12.540699 git.c:455               trace: built-in: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity'

Ubuntu 20.04.3 LTS 上の git 2.25.1 では以下のような出力になる。

$ GIT_CURL_VERBOSE=1 GIT_TRACE=1 git clone https://github.com/kyanny/hello
11:39:28.466447 git.c:439               trace: built-in: git clone https://github.com/kyanny/hello
Cloning into 'hello'...
11:39:28.468728 run-command.c:663       trace: run_command: git-remote-https origin https://github.com/kyanny/hello
* Couldn't find host github.com in the .netrc file; using defaults
*   Trying 52.192.72.89:443...
* TCP_NODELAY set
* Connected to github.com (52.192.72.89) port 443 (#0)
* found 387 certificates in /etc/ssl/certs
* ALPN, offering h2
* ALPN, offering http/1.1
* SSL connection using TLS1.3 / ECDHE_RSA_AES_128_GCM_SHA256
*    server certificate verification OK
*    server certificate status verification SKIPPED
*    common name: github.com (matched)
*    server certificate expiration date OK
*    server certificate activation date OK
*    certificate public key: EC/ECDSA
*    certificate version: #3
*    subject: C=US,ST=California,L=San Francisco,O=GitHub\, Inc.,CN=github.com
*    start date: Thu, 25 Mar 2021 00:00:00 GMT
*    expire date: Wed, 30 Mar 2022 23:59:59 GMT
*    issuer: C=US,O=DigiCert\, Inc.,CN=DigiCert High Assurance TLS Hybrid ECC SHA256 2020 CA1
* ALPN, server accepted to use h2
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x561fca1e18c0)
> GET /kyanny/hello/info/refs?service=git-upload-pack HTTP/2
Host: github.com
user-agent: git/2.25.1
accept: */*
accept-encoding: deflate, gzip, br
accept-language: C, *;q=0.9
pragma: no-cache

* Connection state changed (MAX_CONCURRENT_STREAMS == 100)!
< HTTP/2 200
< server: GitHub Babel 2.0
< content-type: application/x-git-upload-pack-advertisement
< content-security-policy: default-src 'none'; sandbox
< expires: Fri, 01 Jan 1980 00:00:00 GMT
< pragma: no-cache
< cache-control: no-cache, max-age=0, must-revalidate
< vary: Accept-Encoding
< x-frame-options: DENY
< x-github-request-id: E596:70D6:630C58:71FFF2:6130B7F1
<
* Connection #0 to host github.com left intact
11:39:28.735999 run-command.c:663       trace: run_command: git fetch-pack --stateless-rpc --stdin --lock-pack --thin --check-self-contained-and-connected --cloning https://github.com/kyanny/hello/
11:39:28.737966 git.c:439               trace: built-in: git fetch-pack --stateless-rpc --stdin --lock-pack --thin --check-self-contained-and-connected --cloning https://github.com/kyanny/hello/
* Couldn't find host github.com in the .netrc file; using defaults
* Found bundle for host github.com: 0x561fca1e7bf0 [can multiplex]
* Re-using existing connection! (#0) with host github.com
* Connected to github.com (52.192.72.89) port 443 (#0)
* Using Stream ID: 3 (easy handle 0x561fca1e18c0)
> POST /kyanny/hello/git-upload-pack HTTP/2
Host: github.com
user-agent: git/2.25.1
accept-encoding: deflate, gzip, br
content-type: application/x-git-upload-pack-request
accept: application/x-git-upload-pack-result
content-length: 215

* We are completely uploaded and fine
< HTTP/2 200
< server: GitHub Babel 2.0
< content-type: application/x-git-upload-pack-result
< content-security-policy: default-src 'none'; sandbox
< expires: Fri, 01 Jan 1980 00:00:00 GMT
< pragma: no-cache
< cache-control: no-cache, max-age=0, must-revalidate
< vary: Accept-Encoding
< x-frame-options: DENY
< x-github-request-id: E596:70D6:630C64:71FFF9:6130B7F1
<
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (3/3), done.
* 11:39:28.947007 run-command.c:663       trace: run_command: git unpack-objects --pack_header=2,6
Connection #0 to host github.com left intact
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
11:39:28.948537 git.c:439               trace: built-in: git unpack-objects --pack_header=2,6
Unpacking objects: 100% (6/6), 1.18 KiB | 1.18 MiB/s, done.
11:39:28.950322 run-command.c:663       trace: run_command: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity'
11:39:28.951430 git.c:439               trace: built-in: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity'

この差がプラットフォームの違いによるものなのか、Git クライアントのバージョンによるものなのかは調べていないが、Ubuntu で実行した時のログは curl -v の出力そのものなのに対して macOS 上で実行した時のログには http.c と出ているので、Git の新しめのバージョンから自前実装した HTTP クライアントを内蔵してそちらを使うようになった、とかかもしれない(以前は curl/libcurl を使っていた?)