Top Related Projects
Quick Overview
g is a simple, lightweight, and fast Git command-line wrapper written in Go. It provides a more intuitive and user-friendly interface for common Git operations, making version control easier for developers of all skill levels.
Pros
- Simplifies Git commands with intuitive shortcuts
- Cross-platform compatibility (Windows, macOS, Linux)
- No dependencies required, single binary installation
- Actively maintained and regularly updated
Cons
- Limited to a subset of Git commands, not a complete replacement
- May require learning new shortcuts for experienced Git users
- Potential confusion when switching between
gand standard Git commands - Less comprehensive documentation compared to official Git
Code Examples
- Initializing a repository and making the first commit:
g i
g a .
g c "Initial commit"
- Checking status, adding files, and committing changes:
g s
g a src/
g c "Update source files"
- Creating and switching branches:
g b feature-branch
g o feature-branch
- Pushing changes to a remote repository:
g p origin main
Getting Started
-
Install
gusing one of the following methods:- Download the pre-built binary from the releases page
- Use a package manager (e.g., Homebrew on macOS:
brew install stefanmaric/tap/g) - Build from source:
go install github.com/stefanmaric/g@latest
-
Verify the installation:
g --version -
Start using
gin your Git repositories:cd your-project g s # Check status g a . # Add all changes g c "Your commit message" # Commit changes -
Consult the documentation for a full list of available commands and their corresponding Git equivalents.
Competitor Comparisons
A Go library for implementing command-line interfaces.
Pros of cli
- More comprehensive CLI framework with advanced features like subcommands and flags
- Better documentation and examples for developers
- Larger community and more active development
Cons of cli
- More complex to set up and use for simple CLI applications
- Heavier dependency footprint compared to g
- Steeper learning curve for beginners
Code Comparison
cli:
type CLI struct {
Args []string
Commands map[string]CommandFactory
HelpFunc HelpFunc
}
func (cli *CLI) Run() (int, error) {
// Implementation
}
g:
func Run(args []string, commands map[string]Command) error {
// Implementation
}
The cli library provides a more structured approach with a CLI struct and methods, while g offers a simpler function-based interface. cli's implementation allows for more customization and advanced features, but g's approach is more straightforward for basic CLI applications.
Both libraries aim to simplify CLI application development in Go, but they cater to different complexity levels and use cases. cli is better suited for larger, more complex applications with multiple subcommands and options, while g is ideal for simpler CLI tools with basic command structures.
A Commander for modern Go CLI interactions
Pros of Cobra
- More comprehensive and feature-rich CLI framework
- Extensive documentation and community support
- Built-in support for flags, nested subcommands, and auto-generated help
Cons of Cobra
- Steeper learning curve due to its complexity
- Heavier and more resource-intensive
- May be overkill for simple CLI applications
Code Comparison
Cobra:
var rootCmd = &cobra.Command{
Use: "app",
Short: "A brief description of your application",
Run: func(cmd *cobra.Command, args []string) {
// Your code here
},
}
g:
func main() {
g.Command("app", "A brief description of your application", func(c *g.Context) {
// Your code here
})
}
Cobra offers a more structured approach with separate command definitions, while g provides a simpler, more concise syntax for defining commands. Cobra's approach allows for more complex command structures and better separation of concerns, but g's approach is more straightforward for simpler applications.
Both libraries aim to simplify CLI application development in Go, but they cater to different levels of complexity and user needs. Cobra is better suited for large-scale projects with complex command structures, while g is ideal for smaller projects or when rapid development is prioritized.
CONTRIBUTIONS ONLY: A Go (golang) command line and flag parser
Pros of kingpin
- More comprehensive command-line parsing with support for subcommands and flags
- Better documentation and examples for complex use cases
- Wider adoption and community support
Cons of kingpin
- Steeper learning curve for simple use cases
- More verbose syntax for basic flag definitions
- Larger codebase and potential overhead for small projects
Code Comparison
kingpin:
var (
verbose = kingpin.Flag("verbose", "Verbose mode.").Short('v').Bool()
name = kingpin.Arg("name", "Name of user.").Required().String()
)
func main() {
kingpin.Parse()
// ...
}
g:
func main() {
verbose := g.Bool("verbose", false, "Verbose mode")
name := g.String("name", "", "Name of user")
g.Parse()
// ...
}
Summary
kingpin offers more advanced features and better support for complex command-line applications, while g provides a simpler and more lightweight approach for basic flag parsing. kingpin's syntax is more verbose but offers greater flexibility, whereas g focuses on ease of use for straightforward use cases.
The complete solution for Ruby command-line executables
Pros of Commander
- More mature and widely adopted project with a larger community
- Extensive documentation and examples available
- Supports both declarative and programmatic command-line interfaces
Cons of Commander
- Larger package size and more dependencies
- Steeper learning curve for complex use cases
- Less focus on performance optimization
Code Comparison
Commander:
const program = require('commander');
program
.version('0.1.0')
.option('-p, --peppers', 'Add peppers')
.option('-c, --cheese <type>', 'Add cheese')
.parse(process.argv);
g:
const g = require('g');
g()
.version('0.1.0')
.option('p', 'peppers', 'Add peppers')
.option('c', 'cheese', 'Add cheese', '<type>')
.parse();
Both libraries offer similar functionality for creating command-line interfaces, but g focuses on a more concise syntax and smaller footprint. Commander provides more built-in features and flexibility, while g aims for simplicity and performance. The choice between the two depends on the specific requirements of your project and personal preferences.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
g
Simple go version manager, gluten-free.

Why?
Existing version managers build go from source, have too many dependencies, pollute the PATH, and/or require you to use a specific shell environment. g aims to be as unobtrusive and portable as possible.
g is inspired by tj/n - which I have contributed to in the past - and borrows some of its code.
Features
- Run any go version on demand.
- Single portable shell script that ideally lives where your go binaries live.
- Works no matter what shell you use as long as
$GOPATHand$GOROOTare exported which... - ...is idiomatic to
goand not specific tog. - No need to
sourcefunctions in your shell config. - Downloads pre-built binaries so it is fast and...
- ...requires no git, no mercurial, no gcc, no xcode, etc.
curlandwgetfirst-class support alike.- Colorful UI and interactive but safe to pipe and use in automated scripts.
- self-upgrade command to keep up-to-date.
- Option to get go beta versions.
- Get started in golang with a single line using the install script.
- The install script detects name collisions and helps you set an alternative name.
Requirements
- macOS, Linux or BSD environment. Bash for Windows (WSL) is supported as well.
- Either
curlorwget, check withcurl -Vorwget -Vrespectively.
Not strictly necessary, but highly recommended, to completely remove any previous go installation â just to prevent any weird outcome.
Single-line Installation
IMPORTANT: Before you continue, I encourage you to read the install script; never trust someone telling you to run random commands.
That said, you can install g with a single command:
curl -sSL https://git.io/g-install | sh -s
If you use wget instead:
wget -qO- https://git.io/g-install | sh -s
That will download the g script, put it inside $GOPATH/bin/, give it execution rights with chmod, and configure your default shell's initialization file, setting the GOPATH & GOROOT environment variables and adding $GOPATH/bin to the PATH.
Then you will prompted to install the latest version of go; you can skip this step and install your preferred version with g later.
NOTE: You must restart your current shell session for it to read these new env vars in order to use g or go.
Shell support
The install script currently supports the following shells:
- bash
- zsh
- fish
- ash
- dash
- csh
- tcsh
That doesn't mean you cannot use g with other shells, just proceed with the manual installation.
The install script is going to select your default shell for configuration. You might see what your default shell is by running:
echo $SHELL
If you wish to configure a diff shell, you might pass it as arguments:
curl -sSL https://git.io/g-install | sh -s -- fish
You might as well configure several shells, but that's usually not required:
curl -sSL https://git.io/g-install | sh -s -- fish bash zsh
Use the -y option to skip the prompts and assume "yes" for everything:
curl -sSL https://git.io/g-install | sh -s -- -y
Changing defaults
By default, these go environment variables are used:
GOROOT: $HOME/.go
GOPATH: $HOME/go
$GOPATH/bin is added to the PATH and there's where g is copied to.
You might set those variables before running the install script. For example, in bash and zsh:
export GOROOT=~/.local/share/golang
export GOPATH=~/MyProjects/go-projects
curl -sSL https://git.io/g-install | sh -s
In fish:
set -gx GOROOT ~/.local/share/golang
set -gx GOPATH ~/MyProjects/go-projects
curl -sSL https://git.io/g-install | sh -s
Manual Installation
- Make sure to export the
$GOPATH&$GOROOTenvironment variables and add$GOPATH/binto yourPATH. - Grab a copy of the
./bin/gscript and put it anywhere available in yourPATHâ inside$GOPATH/bin/is a good option. - Give the script execution rights with
chmod +x $GOPATH/bin/g. - Restart your shell session to make sure the env variables are loaded.
Upgrading
g includes a self-upgrade command you can run to get the latest version of g. This command simply runs the install script once again.
Usage
Usage: g [COMMAND] [options] [args]
Commands:
g Open interactive UI with downloaded versions
g install latest Download and set the latest go release
g install <version> Download and set go <version>
g download <version> Download go <version>
g set <version> Switch to go <version>
g run <version> Run a given version of go
g which <version> Output bin path for <version>
g remove <version ...> Remove the given version(s)
g prune Remove all versions except the current version
g list Output downloaded go versions
g list-all Output all available, remote go versions
g self-upgrade Upgrades g to the latest version
g help Display help information, same as g --help
Options:
-h, --help Display help information and exit
-v, --version Output current version of g and exit
-q, --quiet Suppress almost all output
-c, --no-color Force disabled color output
-y, --non-interactive Prevent prompts
-o, --os Override operating system
-a, --arch Override system architecture
-u, --unstable Include unstable versions in list
Uninstall
g is a single portable shell script that acts like a binary that's available in your $PATH. If you setup g with the install script, its removal should be pretty straight forward.
First of all, get some info about your system:
echo $SHELL
echo $GOROOT
echo $GOPATH
command -v g
You will notice the g file lives inside your $GOPATH/bin/ directory. If you only want to remove g and keep your currently installed go binaries and related files, simply delete g:
# If you're using bash, zsh, or other POSIX shell:
rm "$(command -v g)"
# If you're using fish:
rm (command -v g)
Now, if you want to remove everything, first be sure to backup your projects inside $GOROOT, if any. Then remove everything inside $GOROOT and $GOPATH:
rm -r $GOPATH $GOROOT
Then open your shell config file with your text editor of choice and look of for a line that includes g-install to remove it. These are the locations usually used by the install script:
# bash on MacOS
~/.bash_profile
# bash on linux/BSD
~/.bashrc
# zsh
~/.zshrc
# fish shell
~/.config/fish/config.fish
# csh
~/.cshrc
# tcsh
~/.tcshrc
# For ash and dash, check your $ENV var
echo $ENV
At this point you would have removed g and go entirely.
TODO
- Improve docs a bit more
- Make
gandg-installPOSIX compliant - Add support for more shells
- Warn users they already have a golang installation when using
g-install - Use better naming for
g install <version>, maybeuseorset. See #8- Use
installonly for install and remove the--downloadoption
- Use
- Handle the case when
galready exists, mainlyzshwithoh-my-zsh- Make it so
g-installoffers the user to setup an alternative alias forg
- Make it so
- Make the
self-upgradecommand throw ifgwas not installed in the common way - Add a
completecommand that generates completions for the supported shells- And have
g-installsetup the shells to call this command for completions
- And have
- Explore feature to configure shells to autoload go versions based on mod.go
- Test it on diff platforms
- Crete a test setup with
docker andGithub actions - Add more tests
The alternatives (and why I prefer g)
- moovweb/gvm
- Too many features.
- Builds from source, i.e, requires gcc, make, xcode, etc.
- Requires git and mercurial.
- Requires bootstrapping, i.e., install go 1.4 first.
- Specific to a shell, i.e., doesn't work with fishshell.
- syndbg/goenv
- Too many features and weird DX.
- Uses an hard-coded list of go versions...
- ...thus you have to upgrade
goenvbefore installing a new version of go. - Adds a lot to your env and PATH.
- hit9/oo
- Pretty much same as
gvm.
- Pretty much same as
- asdf-golang
- Depends on asdf.
- andrewkroh/gvm
- Bash, batch and powershell support only.
- Cumbersome to use.
- MakeNowJust/govm
- Builds from source.
- Requires python 2.
Contributing
Please read CONTRIBUTING.md. â¥
Acknowledgments
- Every contributor to this project.
- The
nproject, whichgis inspired by and based on. - The
n-installproject, whichgis also based on.
License
MIT â¥
Top Related Projects
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot