{"id":20534235,"url":"https://github.com/gookit/gitw","last_synced_at":"2025-08-01T10:04:24.614Z","repository":{"id":37925693,"uuid":"343057141","full_name":"gookit/gitw","owner":"gookit","description":"🛠   Git command wrapper, git emojis, generate changelog, get repo, branch, remote information and some git command tools. Git 命令包装器，生成 git 变更记录日志，获取 repo,branch,remote 信息和一些 git 命令工具。","archived":false,"fork":false,"pushed_at":"2024-07-18T05:22:58.000Z","size":3418,"stargazers_count":26,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-27T20:41:09.801Z","etag":null,"topics":["changelog","changelog-generator","git","git-command","git-commands","git-emojis","git-log","go-git"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/gookit/gitw","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/gookit.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}},"created_at":"2021-02-28T08:36:18.000Z","updated_at":"2024-07-18T05:23:02.000Z","dependencies_parsed_at":"2024-02-07T03:26:51.292Z","dependency_job_id":"32908520-0d11-4a0d-a40e-45bb9d4c8634","html_url":"https://github.com/gookit/gitw","commit_stats":null,"previous_names":["gookit/gitwrap"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fgitw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fgitw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fgitw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fgitw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gookit","download_url":"https://codeload.github.com/gookit/gitw/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248837281,"owners_count":21169374,"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":["changelog","changelog-generator","git","git-command","git-commands","git-emojis","git-log","go-git"],"created_at":"2024-11-16T00:25:54.747Z","updated_at":"2025-04-14T06:53:51.858Z","avatar_url":"https://github.com/gookit.png","language":"Go","readme":"# Gitw\n\n![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/gookit/gitw?style=flat-square)\n[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/gookit/gitw)](https://github.com/gookit/gitw)\n[![Go Reference](https://pkg.go.dev/badge/github.com/gookit/goutil.svg)](https://pkg.go.dev/github.com/gookit/goutil)\n[![Go Report Card](https://goreportcard.com/badge/github.com/gookit/gitw)](https://goreportcard.com/report/github.com/gookit/gitw)\n[![Unit-Tests](https://github.com/gookit/gitw/workflows/Unit-Tests/badge.svg)](https://github.com/gookit/gitw/actions)\n[![Coverage Status](https://coveralls.io/repos/github/gookit/gitw/badge.svg?branch=main)](https://coveralls.io/github/gookit/gitw?branch=main)\n\n`gitw` - Git command wrapper, generate git changelog, fetch repo information and some git tools.\n\n- Wrap local `git` commands \n- Quickly run `git` commands \n- Quickly query repository information \n  - Quick fetch status, remote, branch ... details\n- Quickly generate version changelogs via `git log` \n  - Allow custom build configuration \n  - Allow custom build filtering , styles, etc \n  - can be used directly in GitHub Actions\n- Support git-emoji code search and replace render\n\n\u003e **[中文说明](README.zh-CN.md)**\n\n## Install\n\n\u003e required: go 1.18+, git 2.x\n\n```bash\ngo get github.com/gookit/gitw\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/gookit/gitw\"\n)\n\nfunc main() {\n\t// logTxt, err := gitw.ShowLogs(\"v1.0.2\", \"v1.0.3\")\n\tlogTxt := gitw.MustString(gitw.ShowLogs(\"v1.0.2\", \"v1.0.3\"))\n\tfmt.Println(logTxt)\n\n\t// Local Branches\n\tbrList := gitw.MustStrings(gitw.Branches())\n\tfmt.Println(brList)\n\n\t// custom create command\n\n\tlogCmd := gitw.New(\"log\", \"-2\")\n\t// git.Run()\n\t// txt, err := logCmd.Output()\n\ttxt := logCmd.SafeOutput()\n\n\tfmt.Println(txt)\n}\n```\n\n### With more arguments\n\nExamples, get commit logs between two sha versions via `git log`\n\n```go\n\tlogCmd := gitw.Log(\"--reverse\").\n\t\tArgf(\"--pretty=format:\\\"%s\\\"\", c.cfg.LogFormat)\n\n\tif c.cfg.Verbose {\n\t\tlogCmd.OnBeforeExec(gitw.PrintCmdline)\n\t}\n\n\t// add custom args. eg: \"--no-merges\"\n\tlogCmd.AddArgs(\"--no-merges\")\n\n\t// logCmd.Argf(\"%s...%s\", \"v0.1.0\", \"HEAD\")\n\tif sha1 != \"\" \u0026\u0026 sha2 != \"\" {\n\t\tlogCmd.Argf(\"%s...%s\", sha1, sha2)\n\t}\n\n\tfmt.Println(logCmd.SafeOutput())\n```\n\n## Repository\n\nYou can quickly get a git repository information at local.\n\n```go\nrepo := gitw.NewRepo(\"/path/to/my-repo\")\n```\n\n### Status Information\n\n```go\nsi := repo.StatusInfo()\n\ndump.Println(si)\n```\n\n**Output**:\n\n![repo-status-info](_examples/images/repo-status-info.png)\n\n### Branch Information\n\n```go\nbrInfo := repo.CurBranchInfo()\n\ndump.Println(brInfo)\n```\n\n**Output**:\n\n![one-remote-info](_examples/images/one-branch-info.png)\n\n### Remote Information\n\n```go\nrt := repo.DefaultRemoteInfo()\n\ndump.Println(rt)\n```\n\n**Output**:\n\n![one-remote-info](_examples/images/one-remote-info.png)\n\n### Repo Information\n\n```go\ndump.Println(repo.Info())\n```\n\n**Output**:\n\n![simple-repo-info](_examples/images/simple-repo-info.png)\n\n## Changelog\n\nYou can quickly generate changelog by `gitw/chlog` package.\n\n- Allows custom build configuration. see [.github/changelog.yml](.github/changelog.yml)\n- can set filtering, grouping, output styles, etc.\n\n### Install\n\n```shell\ngo install github.com/gookit/gitw/cmd/chlog@latest\n```\n\n### Usage\n\nPlease run `chlog -h` to see help:\n\n![chlog-help](_examples/images/chlog-help.png)\n\n**Generate changelog**:\n\n```shell\nchlog prev last\nchlog last head\nchlog -c .github/changelog.yml last head\n```\n\n**Outputs**:\n\n![chlog-demo](_examples/images/chlog-demo.png)\n\n### Use on action\n\nCan use `gitw/chlog` on GitHub actions. It does not depend on the Go environment,\njust download the binary files of the corresponding system.\n\nExample:\n\n\u003e Full script please see [.github/workflows/release.yml](.github/workflows/release.yml)\n\n```yaml\n# ...\n\n    steps:\n      - name: Checkout\n        uses: actions/checkout@v3\n        with:\n          fetch-depth: 0\n\n      - name: Generate changelog\n        run: |\n          curl https://github.com/gookit/gitw/releases/latest/download/chlog-linux-amd64 -L -o /usr/local/bin/chlog\n          chmod a+x /usr/local/bin/chlog\n          chlog -c .github/changelog.yml -o changelog.md prev last \n\n```\n\n### Use in code\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/gookit/gitw/chlog\"\n\t\"github.com/gookit/goutil\"\n)\n\nfunc main() {\n\tcl := chlog.New()\n\tcl.Formatter = \u0026chlog.MarkdownFormatter{\n\t\tRepoURL: \"https://github.com/gookit/gitw\",\n\t}\n\tcl.WithConfig(func(c *chlog.Config) {\n\t\t// some settings ...\n\t\tc.Title = \"## Change Log\"\n\t})\n\n\t// fetch git log\n\tcl.FetchGitLog(\"v0.1.0\", \"HEAD\", \"--no-merges\")\n\n\t// do generate\n\tgoutil.PanicIfErr(cl.Generate())\n\n\t// dump\n\tfmt.Println(cl.Changelog())\n}\n```\n\n## Commands\n\n### Methods in `GitWrap`\n\nCommands of git, more please see [pkg.go.dev](https://pkg.go.dev/github.com/gookit/gitw#GitWrap)\n\n```go\nfunc (gw *GitWrap) Add(args ...string) *GitWrap\nfunc (gw *GitWrap) Annotate(args ...string) *GitWrap\nfunc (gw *GitWrap) Apply(args ...string) *GitWrap\nfunc (gw *GitWrap) Bisect(args ...string) *GitWrap\nfunc (gw *GitWrap) Blame(args ...string) *GitWrap\nfunc (gw *GitWrap) Branch(args ...string) *GitWrap\nfunc (gw *GitWrap) Checkout(args ...string) *GitWrap\nfunc (gw *GitWrap) CherryPick(args ...string) *GitWrap\nfunc (gw *GitWrap) Clean(args ...string) *GitWrap\nfunc (gw *GitWrap) Clone(args ...string) *GitWrap\nfunc (gw *GitWrap) Commit(args ...string) *GitWrap\nfunc (gw *GitWrap) Config(args ...string) *GitWrap\nfunc (gw *GitWrap) Describe(args ...string) *GitWrap\nfunc (gw *GitWrap) Diff(args ...string) *GitWrap\nfunc (gw *GitWrap) Fetch(args ...string) *GitWrap\nfunc (gw *GitWrap) Init(args ...string) *GitWrap\nfunc (gw *GitWrap) Log(args ...string) *GitWrap\nfunc (gw *GitWrap) Merge(args ...string) *GitWrap\nfunc (gw *GitWrap) Pull(args ...string) *GitWrap\nfunc (gw *GitWrap) Push(args ...string) *GitWrap\nfunc (gw *GitWrap) Rebase(args ...string) *GitWrap\nfunc (gw *GitWrap) Reflog(args ...string) *GitWrap\nfunc (gw *GitWrap) Remote(args ...string) *GitWrap\n// and more ...\n```\n\n### Commonly git functions\n\nGit command functions of std:\n\n```go\nfunc Alias(name string) string\nfunc AllVars() string\nfunc Branches() ([]string, error)\nfunc CommentChar(text string) (string, error)\nfunc Config(name string) string\nfunc ConfigAll(name string) ([]string, error)\nfunc DataDir() (string, error)\nfunc EditText(data string) string\nfunc Editor() string\nfunc GlobalConfig(name string) (string, error)\nfunc HasDotGitDir(path string) bool\nfunc HasFile(segments ...string) bool\nfunc Head() (string, error)\nfunc Quiet(args ...string) bool\nfunc Ref(ref string) (string, error)\nfunc RefList(a, b string) ([]string, error)\nfunc Remotes() ([]string, error)\nfunc SetGlobalConfig(name, value string) error\nfunc SetWorkdir(dir string)\nfunc ShowDiff(sha string) (string, error)\nfunc ShowLogs(sha1, sha2 string) (string, error)\nfunc Spawn(args ...string) error\nfunc SymbolicFullName(name string) (string, error)\nfunc SymbolicRef(ref string) (string, error)\nfunc Tags(args ...string) ([]string, error)\nfunc Var(name string) string\nfunc Version() (string, error)\nfunc Workdir() (string, error)\nfunc WorkdirName() (string, error)\n```\n\n### Util functions\n\n```go\nfunc SetDebug()\nfunc SetDebug(open bool)\nfunc IsDebug() bool\nfunc IsGitCmd(command string) bool\nfunc IsGitCommand(command string) bool\nfunc IsGitDir(dir string) bool\nfunc ParseRemoteURL(URL string, r *RemoteInfo) (err error)\nfunc MustString(s string, err error) string\nfunc MustStrings(ss []string, err error) []string\nfunc FirstLine(output string) string\nfunc OutputLines(output string) []string\nfunc EditText(data string) string\n```\n\n### Remote info\n\n```go\n// type RemoteInfo\nfunc NewEmptyRemoteInfo(URL string) *RemoteInfo\nfunc NewRemoteInfo(name, url, typ string) (*RemoteInfo, error)\nfunc (r *RemoteInfo) GitURL() string\nfunc (r *RemoteInfo) Invalid() bool\nfunc (r *RemoteInfo) Path() string\nfunc (r *RemoteInfo) RawURLOfHTTP() string\nfunc (r *RemoteInfo) RepoPath() string\nfunc (r *RemoteInfo) String() string\nfunc (r *RemoteInfo) URLOfHTTP() string\nfunc (r *RemoteInfo) URLOfHTTPS() string\nfunc (r *RemoteInfo) Valid() bool\n```\n\n## Refers\n\n- https://github/phppkg/phpgit\n- https://github.com/github/hub\n- https://github.com/alibaba/git-repo-go\n- https://github.com/carloscuesta/gitmoji/blob/master/packages/gitmojis/src/gitmojis.json\n- https://github.com/hooj0/git-emoji-guide\n\n## LICENSE\n\n[MIT](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgookit%2Fgitw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgookit%2Fgitw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgookit%2Fgitw/lists"}