@@ -4,12 +4,36 @@ title: Troubleshooting
44---
55# Troubleshooting
66
7- ## SSH connections
7+ This guide covers common issues encountered when using go-git.
88
9- To enable trace information for SSH handshakes, use the ` GIT_TRACE_SSH `
10- environment variable:
9+ ## Debugging and Tracing
1110
11+ ### Available Trace Options
12+
13+ go-git supports different tracing levels. Enable them by calling ` trace.SetTarget ` :
14+
15+ ``` golang
16+ import ` github.com/go-git/go-git/v6/utils/trace`
17+
18+ ...
19+
20+ trace.SetTarget (trace.SSH | trace.Performance )
21+ ```
22+
23+ Here are the current trace options:
24+
25+ - General: General traces general operations.
26+ - Packet: Packet traces git packets.
27+ - SSH: SSH handshake operations. This does not have a direct translation to an upstream trace option.
28+ - Performance: performance information for specific go-git operations.
29+ - HTTP: HTTP operations and requests.
1230```
31+
32+ ### SSH Connection Issues
33+
34+ To enable trace information for SSH handshakes, use the `GIT_TRACE_SSH` environment variable:
35+
36+ ```bash
1337$ GIT_TRACE_SSH=true go run _examples/clone/main.go git@github.com:go-git/go-git /tmp/go-git
143819:09:14.134147 common.go:43: ssh: Using default auth builder (user: git)
153919:09:14.134193 sshagent.go:42: ssh: net.Dial unix sock /tmp/ssh-XXXXXXULYg1c/agent.6427
@@ -22,3 +46,45 @@ $ GIT_TRACE_SSH=true go run _examples/clone/main.go git@github.com:go-git/go-git
224619:09:14.134577 common.go:155: ssh: host key algorithms [ssh-ed25519]
234719:09:14.458332 auth_method.go:330: ssh: hostkey callback hostname=github.com:22 remote=20.26.156.215:22 pubkey="ssh-ed25519 SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU"
2448```
49+
50+ ## Common Errors and Solutions
51+
52+ ### Performance Issues
53+
54+ #### Large Repository Cloning
55+ ** Problem:** Slow clone times for large repositories
56+
57+ ** Solutions:**
58+ 1 . Use shallow clone:
59+ ``` go
60+ _ , err := git.PlainClone (" /path" , &git.CloneOptions {
61+ URL : " https://github.com/user/repo" ,
62+ Depth : 1 , // Only fetch latest commit
63+ })
64+ ```
65+
66+ 2 . Clone single branch:
67+ ``` go
68+ _ , err := git.PlainClone (" /path" , &git.CloneOptions {
69+ URL : " https://github.com/user/repo" ,
70+ SingleBranch : true ,
71+ ReferenceName : plumbing.NewBranchReferenceName (" main" ),
72+ })
73+ ```
74+
75+ 3 . Skip tags when not needed:
76+ ``` go
77+ _ , err := git.PlainClone (" /path" , &git.CloneOptions {
78+ URL : " https://github.com/user/repo" ,
79+ NoTags : true ,
80+ })
81+ ```
82+
83+ ## Getting Help
84+
85+ If you encounter issues not covered here:
86+
87+ 1 . Check the [ examples directory] ( https://github.com/go-git/go-git/tree/main/_examples ) for usage patterns
88+ 2 . Enable tracing to get detailed debug information
89+ 3 . Review the [ GitHub issues] ( https://github.com/go-git/go-git/issues ) for similar problems
90+ 4 . Create a minimal reproduction case when reporting bugs
0 commit comments