repo¶
Git repository operations for Go — clone, commit, push, branch, inspect trees, and work with worktrees — over go-git, behind focused interfaces that make consumers easy to test.
r, err := repo.NewRepo(repo.Settings{
Forge: repo.ForgeGitHub,
Token: repo.StaticToken(os.Getenv("GITHUB_TOKEN")),
FS: afero.NewOsFs(),
})
Why¶
- No forge dependency. It authenticates to GitHub, GitLab, Bitbucket and Gitea while importing none of them — you pass a forge name and a token, not a forge client. No vendor SDK enters your dependency graph. See why git needs no forge.
- Depend on the narrowest role.
RepoLikeis a composite of small interfaces —TreeReader,Opener,Committer,Brancherand friends. Take the one your code actually uses and mocking becomes trivial. See role interfaces. - In memory or on disk. The same API drives a real checkout or a purely in-memory repository — which makes tests fast and hermetic. See work in memory.
- The worktree is an
afero.Fs. Read and write a checked-out tree with ordinary afero code, live — no copy, no sync step. See read and write the worktree. - Lazy credentials. A token is a
TokenSource, resolved only if the token path is taken — so an SSH-configured repository never triggers a keychain prompt.
Where next¶
- Getting started — clone a repository and read a file from it.
- Clone and commit — the everyday write path.
- Authenticate to a forge — tokens, SSH, and the per-forge conventions.
- Work in memory — hermetic repositories for tests.
- Read and write the worktree — the live
afero.Fsview. - Test with the role mocks — the published
mockspackage.
Reference¶
The API reference is on pkg.go.dev.