A tiny library to run git commands.
Sometimes working with exec.Cmd might not be easy as expected. Here gitgud comes to help you.
Every command has a standard Runnable output. It is similar to the exec.Cmd interface but with some tweaking.
If you need more customisation you can always use the original exec.Cmd instance and tweak it yourself.
- Ease of use
- Handle command errors
- Supports custom
stderr,stdoutandstdin - Run directly in the terminal with
RunInTerminal
go get -u github.com/rawnly/gitgudpackage main
import (
"fmt"
"github.com/rawnly/gitgud/git"
)
func main() {
// equivalent to "git status -s"
status, err := git.Status(&git.StatusOptions{
Short: true,
}).Output()
if err != nil {
panic(err.Error())
}
fmt.Println(status)
} Advanced Example
package main
import "github.com/rawnly/gitgud/git"
import "os"
func main() {
diffCmd := git.Commit("docs(readme): updated example", nil)
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
diffCmd.Cmd.Stdout = stdout
diffCmd.Cmd.Stderr = stderr
if err := diffCmd.Run(); err != nil {
panic(err)
}
}If you're missing some commands you can always use run.Git to manually run git commands.
package main
import (
"fmt"
"github.com/rawnly/gitgud/run"
)
func main() {
// equivalent to "git status -s"
status, err := run.Git("status", "-s").Output()
if err != nil {
panic(err.Error())
}
fmt.Println(status)
}- Clone
- Init
- Add (partially done)
- Mv
- Restore
- Rm
- Bisect
- Diff
- Grep
- Log
- Show
- Status
- Branch
- Checkout
- Commit
- Merge
- Rebase
- Reset
- Switch
- Tag
- Fetch
- Push
- Pull
- Config, SetConfig