Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ go-git is a highly extensible Git implementation in pure Go. This documentation

```go
import (
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v6"
)

func main() {
// Clone repository
repo, err := git.PlainClone("/path/to/repo", false, &git.CloneOptions{
repo, err := git.PlainClone("/path/to/repo", &git.CloneOptions{
URL: "https://github.com/go-git/go-git",
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/tutorials/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ operations using the latest version of go-git.
The following example shows how to clone a Git repository to your local filesystem:

```go
r, err := git.PlainClone("/path/to/repo", false, &git.CloneOptions{
r, err := git.PlainClone("/path/to/repo", &git.CloneOptions{
URL: "https://github.com/go-git/go-git",
})
```
Expand Down
72 changes: 69 additions & 3 deletions src/tutorials/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,36 @@ title: Troubleshooting
---
# Troubleshooting

## SSH connections
This guide covers common issues encountered when using go-git.

To enable trace information for SSH handshakes, use the `GIT_TRACE_SSH`
environment variable:
## Debugging and Tracing

### Available Trace Options

go-git supports different tracing levels. Enable them by calling `trace.SetTarget`:

```golang
import `github.com/go-git/go-git/v6/utils/trace`

...

trace.SetTarget(trace.SSH | trace.Performance)
```

Here are the current trace options:

- General: General traces general operations.
- Packet: Packet traces git packets.
- SSH: SSH handshake operations. This does not have a direct translation to an upstream trace option.
- Performance: performance information for specific go-git operations.
- HTTP: HTTP operations and requests.
```

### SSH Connection Issues

To enable trace information for SSH handshakes, use the `GIT_TRACE_SSH` environment variable:

```bash
$ GIT_TRACE_SSH=true go run _examples/clone/main.go git@github.com:go-git/go-git /tmp/go-git
19:09:14.134147 common.go:43: ssh: Using default auth builder (user: git)
19:09:14.134193 sshagent.go:42: ssh: net.Dial unix sock /tmp/ssh-XXXXXXULYg1c/agent.6427
Expand All @@ -22,3 +46,45 @@ $ GIT_TRACE_SSH=true go run _examples/clone/main.go git@github.com:go-git/go-git
19:09:14.134577 common.go:155: ssh: host key algorithms [ssh-ed25519]
19: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"
```

## Common Errors and Solutions

### Performance Issues

#### Large Repository Cloning
**Problem:** Slow clone times for large repositories

**Solutions:**
1. Use shallow clone:
```go
_, err := git.PlainClone("/path", &git.CloneOptions{
URL: "https://github.com/user/repo",
Depth: 1, // Only fetch latest commit
})
```

2. Clone single branch:
```go
_, err := git.PlainClone("/path", &git.CloneOptions{
URL: "https://github.com/user/repo",
SingleBranch: true,
ReferenceName: plumbing.NewBranchReferenceName("main"),
})
```

3. Skip tags when not needed:
```go
_, err := git.PlainClone("/path", &git.CloneOptions{
URL: "https://github.com/user/repo",
NoTags: true,
})
```

## Getting Help

If you encounter issues not covered here:

1. Check the [examples directory](https://github.com/go-git/go-git/tree/main/_examples) for usage patterns
2. Enable tracing to get detailed debug information
3. Review the [GitHub issues](https://github.com/go-git/go-git/issues) for similar problems
4. Create a minimal reproduction case when reporting bugs