{"id":28906845,"url":"https://github.com/zbiljic/gitexec","last_synced_at":"2026-05-02T05:04:59.727Z","repository":{"id":299575107,"uuid":"1002290098","full_name":"zbiljic/gitexec","owner":"zbiljic","description":"Wrapper around Git command-line operations in Go","archived":false,"fork":false,"pushed_at":"2025-06-17T07:44:59.000Z","size":124,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-17T08:36:30.491Z","etag":null,"topics":["command-line","git","go","golang","wrapper"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zbiljic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-15T06:15:00.000Z","updated_at":"2025-06-17T07:45:02.000Z","dependencies_parsed_at":"2025-06-17T08:36:35.739Z","dependency_job_id":"edf402eb-6464-467b-bc95-ea3462ab1551","html_url":"https://github.com/zbiljic/gitexec","commit_stats":null,"previous_names":["zbiljic/gitexec"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zbiljic/gitexec","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbiljic%2Fgitexec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbiljic%2Fgitexec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbiljic%2Fgitexec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbiljic%2Fgitexec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zbiljic","download_url":"https://codeload.github.com/zbiljic/gitexec/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbiljic%2Fgitexec/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261143160,"owners_count":23115677,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line","git","go","golang","wrapper"],"created_at":"2025-06-21T15:10:16.011Z","updated_at":"2026-05-02T05:04:59.720Z","avatar_url":"https://github.com/zbiljic.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gitexec\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/zbiljic/gitexec.svg)](https://pkg.go.dev/github.com/zbiljic/gitexec)\n[![Go Report Card](https://goreportcard.com/badge/github.com/zbiljic/gitexec)](https://goreportcard.com/report/github.com/zbiljic/gitexec)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\n\n`gitexec` is a Go library that provides a type-safe and structured wrapper around the Git command-line interface. It simplifies executing Git commands from Go applications by abstracting away the complexities of command-line argument construction and execution.\n\n## Why `gitexec`?\n\nInteracting with Git from a Go application often means manually constructing arguments for `os/exec`. This can be tedious, error-prone, and hard to maintain, especially for commands with many flags.\n\n`gitexec` solves this by:\n\n- **Providing a Type-Safe API**: Each Git command has a dedicated function and a corresponding `Options` struct. This makes discovering and using Git options as simple as filling in a struct field, with the benefits of compile-time checks and IDE autocompletion.\n- **Leveraging the Power of Native Git**: By wrapping the `git` CLI, `gitexec` ensures 100% compatibility with all features, configurations, and authentication methods of your installed Git version. You don't have to worry about a reimplementation's limitations.\n- **Simplifying Output Handling**: Each command function returns the combined output (`[]byte`) and an `error`, providing a consistent and straightforward way to handle command results.\n\n## Features\n\n- **Auto-generated Wrappers**: Command wrappers are generated directly from Git's documentation, ensuring accuracy and making it easy to add support for new commands.\n- **Comprehensive Option Structs**: Each command's `Options` struct mirrors the available command-line flags, complete with documentation.\n- **Simple and Consistent API**: All generated commands follow the same `gitexec.Command(opts)` pattern.\n- **Cross-Platform**: Handles process management details for Unix and Windows systems.\n- **Context Support**: Any generated command can be canceled by setting `CmdContext`, and arbitrary subcommands can use `gitexec.CommandContext()`.\n- **Generic Command Execution**: A `gitexec.Command()` function is available for running arbitrary or not-yet-generated Git commands.\n\n## Installation\n\n```sh\ngo get github.com/zbiljic/gitexec\n```\n\n## Usage\n\nAll you need is a standard Git installation available in your system's `PATH`.\n\n### Example: Get the current status\n\nThis example runs `git status --short --branch` in the specified directory.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/zbiljic/gitexec\"\n)\n\nfunc main() {\n\toutput, err := gitexec.Status(\u0026gitexec.StatusOptions{\n\t\tCmdDir: \"/path/to/your/repo\",\n\t\tShort:  true,\n\t\tBranch: true,\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(\"git status failed: %v\\nOutput: %s\", err, string(output))\n\t}\n\n\tfmt.Println(\"Git Status:\")\n\tfmt.Println(string(output))\n}\n```\n\n### Example: Get the last 5 commit logs\n\nThis example runs `git log --max-count=5 --oneline --graph`.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/zbiljic/gitexec\"\n)\n\nfunc main() {\n\toutput, err := gitexec.Log(\u0026gitexec.LogOptions{\n\t\tCmdDir:   \"/path/to/your/repo\",\n\t\tMaxCount: 5,\n\t\tOneline:  true,\n\t\tGraph:    true,\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(\"git log failed: %v\\nOutput: %s\", err, string(output))\n\t}\n\n\tfmt.Println(\"Recent Commits:\")\n\tfmt.Println(string(output))\n}\n```\n\n### Example: Cancel a running command\n\nThis example cancels a `git fetch` if it takes longer than 10 seconds.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"log\"\n\t\"time\"\n\n\t\"github.com/zbiljic/gitexec\"\n)\n\nfunc main() {\n\tctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)\n\tdefer cancel()\n\n\toutput, err := gitexec.Fetch(\u0026gitexec.FetchOptions{\n\t\tCmdDir:     \"/path/to/your/repo\",\n\t\tCmdContext: ctx,\n\t\tAll:        true,\n\t})\n\tif err != nil {\n\t\tif errors.Is(err, context.DeadlineExceeded) {\n\t\t\tlog.Printf(\"git fetch timed out\\nOutput: %s\", string(output))\n\t\t\treturn\n\t\t}\n\t\tlog.Fatalf(\"git fetch failed: %v\\nOutput: %s\", err, string(output))\n\t}\n}\n```\n\n### Example: Running an arbitrary command\n\nFor commands that are not yet generated, or to pass arguments in a more dynamic way, you can use the generic `gitexec.Command` or `gitexec.CommandContext` functions. This example runs `git config core.filemode false` inside a repository.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/zbiljic/gitexec\"\n)\n\nfunc main() {\n\trepoPath := \"/path/to/your/repo\"\n\n\t// Use gitexec.Command for any git subcommand.\n\t// The first argument to Command is the working directory.\n\t// The second is the command name, followed by its arguments.\n\toutput, err := gitexec.Command(repoPath, \"config\", \"core.filemode\", \"false\")\n\tif err != nil {\n\t\t// 'git config' produces no output on success, so output here is for debugging.\n\t\tlog.Fatalf(\"git config failed: %v\\nOutput: %s\", err, string(output))\n\t}\n\n\tfmt.Printf(\"Successfully set 'core.filemode = false' in %s\\n\", repoPath)\n}\n```\n\n## Supported Commands\n\n`gitexec` provides generated, type-safe wrappers for the following Git commands:\n\n- `add`\n- `branch`\n- `clone`\n- `commit`\n- `diff`\n- `fetch`\n- `gc`\n- `log`\n- `ls-remote`\n- `pull`\n- `reset`\n- `rev-list`\n- `rev-parse`\n- `status`\n- `symbolic-ref`\n\n## Contributing\n\nContributions are welcome! If you find a bug, have a feature request, or want to improve the codebase, please feel free to open an issue or submit a pull request.\n\n### Adding a New Command\n\nThe core of this library is its code generator, which parses JSON definitions of Git commands. To add support for a new command:\n\n1.  Create a JSON file in the `docs/git/` directory that describes the command's name, description, and options. Follow the format of the existing JSON files.\n2.  Run the code generator:\n    ```sh\n    go generate ./...\n    # or\n    mise run generate\n    ```\n3.  This will create a new `git-\u003ccommand\u003e_gen.go` file in the root directory.\n4.  Commit the new JSON file and the generated Go file (following pattern of previous commit messages), and open a pull request.\n\n### Development\n\nThe project uses `mise` to manage development tools. To install them, run:\n\n```sh\nmake bootstrap\n```\n\nList available project tasks with:\n\n```sh\nmise tasks\n```\n\nCommon development tasks:\n\n- `mise run tidy`: Tidy Go modules.\n- `mise run fmt`: Format Go code with `gofumpt`.\n- `mise run lint`: Lint the source code and verify module files.\n- `mise run generate`: Run code generation.\n- `mise run pre-commit`: Run formatters and linters.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbiljic%2Fgitexec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzbiljic%2Fgitexec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbiljic%2Fgitexec/lists"}