for zgen

April 12, 2026 ยท View on GitHub

๐Ÿ’ค forgit

Utility tool for using git interactively. Powered by junegunn/fzf.

pre-commit Contributors

This tool is designed to help you use git more efficiently. It's lightweight and easy to use.

๐Ÿ“ Features

ga - Interactive git add selector:

screenshot

glo - Interactive git log viewer:

screenshot

gi - Interactive .gitignore generator:

screenshot

Full Command List

CommandDescription
gaInteractive git add selector
gdInteractive git diff viewer
giInteractive .gitignore generator
gloInteractive git log viewer
gatInteractive .gitattributes generator
gsoInteractive git show viewer
grhInteractive git reset HEAD <file> selector
gcfInteractive git checkout <file> selector
gcffInteractive git checkout <file> from <commit> selector
gcbInteractive git checkout <branch> selector
gswInteractive git switch <branch> selector
gbdInteractive git branch -D <branch> selector
gctInteractive git checkout <tag> selector
gcoInteractive git checkout <commit> selector
grcInteractive git revert <commit> selector
gssInteractive git stash viewer
gspInteractive git stash push selector
gcpInteractive git cherry-pick selector
grbInteractive git rebase -i selector
grlInteractive git reflog viewer
gblInteractive git blame selector
gfuInteractive git commit --fixup && git rebase -i --autosquash selector
gsqInteractive git commit --squash && git rebase -i --autosquash selector
grwInteractive git commit --fixup=reword && git rebase -i --autosquash selector
gcleanInteractive git clean selector
gwtInteractive git worktree selector
gwaInteractive git worktree add selector
gwdInteractive git worktree remove selector

๐Ÿ“ฅ Installation

Requirements

  • fzf version 0.60.0 or higher

    If your OS package manager bundles an older version of fzf, you might install it using fzf's own install script.

Shell Package Managers

# for zplug
zplug 'wfxr/forgit'

# for zgen
zgen load 'wfxr/forgit'

# for antigen
antigen bundle 'wfxr/forgit'

# for fisher (requires fisher v4.4.3 or higher)
fisher install wfxr/forgit

# for omf
omf install https://github.com/wfxr/forgit

# for zinit
zinit load wfxr/forgit

# for oh-my-zsh
git clone https://github.com/wfxr/forgit.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/forgit

# for sheldon.cli
[plugins.forgit]
github = "wfxr/forgit"
rev = "26.01.0"  # check https://github.com/wfxr/forgit/releases for latest version
use = ["forgit.plugin.zsh"]
apply = ["source"]

# manually
# Clone the repository and source it in your shell's rc file or put bin/git-forgit into your $PATH

Homebrew

To install using brew

brew install forgit

Then add the following to your shell's config file:

# Fish:
# ~/.config/fish/config.fish:
[ -f $HOMEBREW_PREFIX/share/forgit/forgit.plugin.fish ]; and source $HOMEBREW_PREFIX/share/forgit/forgit.plugin.fish

# Zsh:
# ~/.zshrc:
[ -f $HOMEBREW_PREFIX/share/forgit/forgit.plugin.zsh ] && source $HOMEBREW_PREFIX/share/forgit/forgit.plugin.zsh

# Bash:
# ~/.bashrc:
[ -f $HOMEBREW_PREFIX/share/forgit/forgit.plugin.sh ] && source $HOMEBREW_PREFIX/share/forgit/forgit.plugin.sh

Arch User Repository

AUR packages, maintained by the developers of forgit, are available. Install the forgit package for the latest release or forgit-git to stay up to date with the latest commits from the default branch of this repository.

Completions

Forgit offers completions for all supported shells. Completions are automatically configured when installing forgit through Homebrew or the AUR. All other installation methods mentioned above require manual setup for completions. The necessary steps depend on the shell you use.

Bash

  • Put completions/git-forgit.bash in ~/.local/share/bash-completion/completions to have bash tab completion for git forgit and configured git aliases.
  • Source completions/git-forgit.bash explicitly to have bash tab completion for forgit shell functions and aliases (e.g., gsw <tab> completes branches).

Fish

  • Put completions/git-forgit.fish in ~/.config/fish/completions/ to have fish tab completion for git forgit and configured git aliases, as well as shell command aliases, such as ga.

Zsh

  • Put completions/_git-forgit in a directory in your $fpath (e.g., /usr/share/zsh/site-functions) to have zsh tab completion for git forgit and configured git aliases, as well as shell command aliases, such as forgit::add and ga.

If you're having issues after updating, and commands such as forgit::add or aliases ga aren't working, remove your completions cache and restart your shell.

> rm ~/.zcompdump
> zsh

๐Ÿš€ Usage

Shell Aliases

You can change the default aliases by defining these variables below before sourcing the forgit shell plugin. (To disable all aliases, Set the FORGIT_NO_ALIASES flag.)

forgit_log=glo
forgit_reflog=grl
forgit_diff=gd
forgit_show=gso
forgit_add=ga
forgit_reset_head=grh
forgit_ignore=gi
forgit_attributes=gat
forgit_checkout_file=gcf
forgit_checkout_file_from_commit=gcff
forgit_checkout_branch=gcb
forgit_switch_branch=gsw
forgit_branch_delete=gbd
forgit_checkout_tag=gct
forgit_checkout_commit=gco
forgit_revert_commit=grc
forgit_clean=gclean
forgit_stash_show=gss
forgit_stash_push=gsp
forgit_cherry_pick=gcp
forgit_rebase=grb
forgit_blame=gbl
forgit_fixup=gfu
forgit_squash=gsq
forgit_reword=grw
forgit_worktree=gwt
forgit_worktree_add=gwa
forgit_worktree_delete=gwd

Git Integration

You can use forgit as a sub-command of git by making git-forgit available in $PATH:

# after `forgit` was loaded
PATH="$PATH:$FORGIT_INSTALL_DIR/bin"

Some plugin managers can help do this.

Then, any forgit command will be a sub-command of git:

git forgit log
git forgit add
git forgit diff

Optionally you can add aliases in git:

git config --global alias.cf 'forgit checkout_file'

And use forgit functions via a git alias:

git cf

โš™ Configuration

Options can be set via environment variables. They have to be exported in order to be recognized by forgit.

For instance, if you want to order branches in gcb by the last committed date you could:

export FORGIT_CHECKOUT_BRANCH_BRANCH_GIT_OPTS='--sort=-committerdate'

Per-command Options

Each forgit command can be customized with dedicated environment variables for git arguments and fzf options:

CommandGit OptionsFZF Options
gaFORGIT_ADD_GIT_OPTSFORGIT_ADD_FZF_OPTS
gloFORGIT_LOG_GIT_OPTSFORGIT_LOG_FZF_OPTS
grlFORGIT_REFLOG_GIT_OPTSFORGIT_REFLOG_FZF_OPTS
giFORGIT_IGNORE_FZF_OPTS
gatFORGIT_ATTRIBUTES_FZF_OPTS
gdFORGIT_DIFF_GIT_OPTSFORGIT_DIFF_FZF_OPTS
gsoFORGIT_SHOW_GIT_OPTSFORGIT_SHOW_FZF_OPTS
grhFORGIT_RESET_HEAD_GIT_OPTSFORGIT_RESET_HEAD_FZF_OPTS
gcfFORGIT_CHECKOUT_FILE_GIT_OPTSFORGIT_CHECKOUT_FILE_FZF_OPTS
gcffFORGIT_SHOW_GIT_OPTS
FORGIT_CHECKOUT_FILE_GIT_OPTS
FORGIT_CHECKOUT_FILE_FROM_COMMIT_LOG_FZF_OPTS
FORGIT_CHECKOUT_FILE_FROM_COMMIT_SHOW_FZF_OPTS
gcbFORGIT_CHECKOUT_BRANCH_GIT_OPTS
FORGIT_CHECKOUT_BRANCH_BRANCH_GIT_OPTS
FORGIT_CHECKOUT_BRANCH_FZF_OPTS
gswFORGIT_SWITCH_BRANCH_GIT_OPTSFORGIT_SWITCH_BRANCH_FZF_OPTS
gbdFORGIT_BRANCH_DELETE_GIT_OPTSFORGIT_BRANCH_DELETE_FZF_OPTS
gctFORGIT_CHECKOUT_TAG_GIT_OPTSFORGIT_CHECKOUT_TAG_FZF_OPTS
gcoFORGIT_CHECKOUT_COMMIT_GIT_OPTSFORGIT_CHECKOUT_COMMIT_FZF_OPTS
grcFORGIT_REVERT_COMMIT_GIT_OPTSFORGIT_REVERT_COMMIT_FZF_OPTS
gssFORGIT_STASH_SHOW_GIT_OPTSFORGIT_STASH_FZF_OPTS
gspFORGIT_STASH_PUSH_GIT_OPTSFORGIT_STASH_PUSH_FZF_OPTS
gcleanFORGIT_CLEAN_GIT_OPTSFORGIT_CLEAN_FZF_OPTS
gcpFORGIT_CHERRY_PICK_GIT_OPTSFORGIT_CHERRY_PICK_FZF_OPTS
grbFORGIT_REBASE_GIT_OPTSFORGIT_REBASE_FZF_OPTS
gblFORGIT_BLAME_GIT_OPTSFORGIT_BLAME_FZF_OPTS
gfuFORGIT_FIXUP_GIT_OPTSFORGIT_FIXUP_FZF_OPTS
gsqFORGIT_SQUASH_GIT_OPTSFORGIT_SQUASH_FZF_OPTS
grwFORGIT_REWORD_GIT_OPTSFORGIT_REWORD_FZF_OPTS
gwtFORGIT_WORKTREE_FZF_OPTS
gwaFORGIT_WORKTREE_ADD_BRANCH_GIT_OPTSFORGIT_WORKTREE_ADD_FZF_OPTS
gwdFORGIT_WORKTREE_DELETE_GIT_OPTSFORGIT_WORKTREE_DELETE_FZF_OPTS

Pagers

Forgit will use the default configured pager from git (core.pager, pager.show, pager.diff) but can be altered with the following environment variables:

PagerFallbacks to
FORGIT_PAGERgit config core.pager or cat
FORGIT_SHOW_PAGERgit config pager.show or $FORGIT_PAGER
FORGIT_DIFF_PAGERgit config pager.diff or $FORGIT_PAGER
FORGIT_BLAME_PAGERgit config pager.blame or $FORGIT_PAGER
FORGIT_IGNORE_PAGERbat -l gitignore --color always or cat
FORGIT_ATTRIBUTES_PAGERbat -l gitattributes --color always or cat
FORGIT_PREVIEW_PAGERNormal pager resolution*

* If your pager is a TUI program (e.g., diffnav, tig), fzf preview panes will be blank because they run without a TTY. Set FORGIT_PREVIEW_PAGER to a non-interactive pager (e.g., delta) to fix this. When set, it overrides all other FORGIT_*_PAGER settings in fzf preview context.

FZF Options

You can add default fzf options for forgit, including keybindings, layout, etc. (No need to repeat the options already defined in FZF_DEFAULT_OPTS)

export FORGIT_FZF_DEFAULT_OPTS="
--exact
--border
--cycle
--reverse
--height '80%'
"

Per-command fzf options (FORGIT_*_FZF_OPTS) are listed in the per-command options table above.

Complete loading order of fzf options is:

  1. FZF_DEFAULT_OPTS (fzf global)
  2. FORGIT_FZF_DEFAULT_OPTS (forgit global)
  3. FORGIT_CMD_FZF_OPTS (command specific)

Examples:

  • ctrl-d to drop the selected stash but do not quit fzf (gss specific).
export FORGIT_STASH_FZF_OPTS='
--bind="ctrl-d:reload(git stash drop $(cut -d: -f1 <<<{}) 1>/dev/null && git stash list)"
'
  • ctrl-e to view the logs in a vim buffer (glo specific).
export FORGIT_LOG_FZF_OPTS='
--bind="ctrl-e:execute(echo {} |grep -Eo [a-f0-9]+ |head -1 |xargs git show |vim -)"
'

Other Options

OptionDescriptionDefault
FORGIT_LOG_FORMATgit log format%C(auto)%h%d %s %C(black)%C(bold)%cr%Creset
FORGIT_GLO_FORMAToverride log format for glo command$FORGIT_LOG_FORMAT
FORGIT_LOG_GRAPH_ENABLEenable log graph displaytrue
FORGIT_COPY_CMDcommand for copying to clipboardpbcopy
FORGIT_PREVIEW_CONTEXTlines of diff context in preview mode3
FORGIT_FULLSCREEN_CONTEXTlines of diff context in full-screen mode10
FORGIT_DIR_VIEWcommand used to preview directoriestree if available, otherwise find
FORGIT_CLEAN_LIST_FILES_OPTSarguments passed to git ls-files together with --others to determine which files are shown when invoking forgit clean
FORGIT_WORKTREE_ADD_DIRdirectory where new worktrees are created<repo-root>/.wt

โŒจ Keybindings

KeyAction
EnterConfirm
TabToggle mark and move down
Shift - TabToggle mark and move up
?Toggle preview window
Alt - WToggle preview wrap
Ctrl - SToggle sort
Ctrl - RToggle selection
Ctrl - YCopy commit hash/stash ID/worktree path1
Ctrl - K / PSelection move up
Ctrl - J / NSelection move down
Alt - K / PPreview move up
Alt - J / NPreview move down
Alt - EOpen file in default editor (when possible)
Alt - TShow commit message (when viewing a commit)
Alt - LToggle worktree lock/unlock2

1 Available when the selection contains a commit hash, stash ID, or worktree path.

2 Available in the worktree browser (gwt) and worktree delete selector (gwd).

For Linux users FORGIT_COPY_CMD should be set to make copy work. Example: FORGIT_COPY_CMD='xclip -selection clipboard'.

๐Ÿ“ฆ Optional dependencies

  • delta / diff-so-fancy: For better human-readable diffs.

  • bat: Syntax highlighting for gitignore and gitattributes.

  • emoji-cli: Emoji support for git log.

  • tree: Directory tree view for gclean.

๐Ÿ’ก Tips

  • Most of the commands accept optional arguments (e.g., glo develop, glo f738479..188a849b -- main.go, gco main).
  • gd supports specifying revision (e.g., gd HEAD~, gd v1.0 README.md).
  • Call gi or gat with arguments to get the wanted .gitignore/.gitattributes contents directly (e.g., gi cmake c++).

โš’๏ธ Contributing

Contributions are welcome. For the repository-specific contribution workflow, local validation steps, and commit message guidelines, see CONTRIBUTING.md.

โญ Star History

Star History Chart

๐Ÿ“ƒ License

MIT (c) Wenxuan Zhang