Home

Awesome

<h1 align="center">💤 forgit</h1> <p align="center"> <em>Utility tool for using git interactively. Powered by <a href="https://github.com/junegunn/fzf">junegunn/fzf</a>.</em> </p> <p align="center"> <a href="https://github.com/wfxr/forgit/actions"> <img src="https://github.com/wfxr/forgit/workflows/ci/badge.svg"/> </a> <a href="https://wfxr.mit-license.org/2017"> <img src="https://img.shields.io/badge/License-MIT-brightgreen.svg"/> </a> <a href="https://img.shields.io/badge/Shell-Bash%20%7C%20Zsh%20%7C%20Fish-blue"> <img src="https://img.shields.io/badge/Shell-Bash%20%7C%20Zsh%20%7C%20Fish-blue"/> </a> <a href="https://github.com/unixorn/awesome-zsh-plugins"> <img src="https://img.shields.io/badge/Awesome-zsh--plugins-d07cd0?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAABVklEQVRIS+3VvWpVURDF8d9CRAJapBAfwWCt+FEJthIUUcEm2NgIYiOxsrCwULCwktjYKSgYLfQF1JjCNvoMNhYRCwOO7HAiVw055yoBizvN3nBmrf8+M7PZsc2RbfY3AfRWeNMSVdUlHEzS1t6oqvt4n+TB78l/AKpqHrdwLcndXndU1WXcw50k10c1PwFV1fa3cQVzSR4PMd/IqaoLeIj2N1eTfG/f1gFVtQMLOI+zSV6NYz4COYFneIGLSdZSVbvwCMdxMsnbvzEfgRzCSyzjXAO8xlHcxMq/mI9oD+AGlhqgxjD93OVOD9TUuICdXd++/VeAVewecKKv2NPlfcHUAM1qK9FTnBmQvJjkdDfWzzE7QPOkAfZiEce2ECzhVJJPHWAfGuTwFpo365pO0NYjmEFr5Eas4SPeJfll2rqb38Z7/yaaD+0eNM3kPejt86REvSX6AamgdXkgoxLxAAAAAElFTkSuQmCC"/> </a> <a href="https://github.com/pre-commit/pre-commit"> <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white" alt="pre-commit" /> </a> <a href="https://github.com/wfxr/forgit/graphs/contributors"> <img src="https://img.shields.io/github/contributors/wfxr/forgit" alt="Contributors"/> </a> </p>

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

📥 Installation

Make sure you have fzf installed.

# 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

# 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

Fig

Fig adds apps, shortcuts, and autocomplete to your existing terminal.

Install forgit in just one click.

Install with Fig

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 master branch of this repository.

📝 Features

screenshot

screenshot

The log graph can be disabled by option FORGIT_LOG_GRAPH_ENABLE (see discuss in issue #71).

screenshot

⌨ Keybindings

KeyAction
<kbd>Enter</kbd>Confirm
<kbd>Tab</kbd>Toggle mark and move down
<kbd>Shift</kbd> - <kbd>Tab</kbd>Toggle mark and move up
<kbd>?</kbd>Toggle preview window
<kbd>Alt</kbd> - <kbd>W</kbd>Toggle preview wrap
<kbd>Ctrl</kbd> - <kbd>S</kbd>Toggle sort
<kbd>Ctrl</kbd> - <kbd>R</kbd>Toggle selection
<kbd>Ctrl</kbd> - <kbd>Y</kbd>Copy commit hash/stash ID*
<kbd>Ctrl</kbd> - <kbd>K</kbd> / <kbd>P</kbd>Selection move up
<kbd>Ctrl</kbd> - <kbd>J</kbd> / <kbd>N</kbd>Selection move down
<kbd>Alt</kbd> - <kbd>K</kbd> / <kbd>P</kbd>Preview move up
<kbd>Alt</kbd> - <kbd>J</kbd> / <kbd>N</kbd>Preview move down
<kbd>Alt</kbd> - <kbd>E</kbd>Open file in default editor (when possible)

* Available when the selection contains a commit hash or a stash ID. For Linux users FORGIT_COPY_CMD should be set to make copy work. Example: FORGIT_COPY_CMD='xclip -selection clipboard'.

⚙ Options

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'

shell aliases

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

forgit_log=glo
forgit_diff=gd
forgit_add=ga
forgit_reset_head=grh
forgit_ignore=gi
forgit_checkout_file=gcf
forgit_checkout_branch=gcb
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

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

git options

If you want to customize git's behavior within forgit there is a dedicated variable for each forgit command. These are passed to the according git calls.

CommandOption
gaFORGIT_ADD_GIT_OPTS
gloFORGIT_LOG_GIT_OPTS
gdFORGIT_DIFF_GIT_OPTS
grhFORGIT_RESET_HEAD_GIT_OPTS
gcfFORGIT_CHECKOUT_FILE_GIT_OPTS
gcbFORGIT_CHECKOUT_BRANCH_GIT_OPTS, FORGIT_CHECKOUT_BRANCH_BRANCH_GIT_OPTS
gbdFORGIT_BRANCH_DELETE_GIT_OPTS
gctFORGIT_CHECKOUT_TAG_GIT_OPTS
gcoFORGIT_CHECKOUT_COMMIT_GIT_OPTS
grcFORGIT_REVERT_COMMIT_GIT_OPTS
gssFORGIT_STASH_SHOW_GIT_OPTS
gspFORGIT_STASH_PUSH_GIT_OPTS
gcleanFORGIT_CLEAN_GIT_OPTS
grbFORGIT_REBASE_GIT_OPTS
gblFORGIT_BLAME_GIT_OPTS
gfuFORGIT_FIXUP_GIT_OPTS
gcpFORGIT_CHERRY_PICK_GIT_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:

Use caseOptionFallbacks to
common pagerFORGIT_PAGERgit config core.pager or cat
pager on git showFORGIT_SHOW_PAGERgit config pager.show or $FORGIT_PAGER
pager on git diffFORGIT_DIFF_PAGERgit config pager.diff or $FORGIT_PAGER
pager on git blameFORGIT_BLAME_PAGERgit config pager.blame or $FORGIT_PAGER
pager on gitignoreFORGIT_IGNORE_PAGERbat -l gitignore --color always or cat
git log formatFORGIT_GLO_FORMAT%C(auto)%h%d %s %C(black)%C(bold)%cr%reset

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%'
"

Customizing fzf options for each command individually is also supported:

CommandOption
gaFORGIT_ADD_FZF_OPTS
gloFORGIT_LOG_FZF_OPTS
giFORGIT_IGNORE_FZF_OPTS
gdFORGIT_DIFF_FZF_OPTS
grhFORGIT_RESET_HEAD_FZF_OPTS
gcfFORGIT_CHECKOUT_FILE_FZF_OPTS
gcbFORGIT_CHECKOUT_BRANCH_FZF_OPTS
gbdFORGIT_BRANCH_DELETE_FZF_OPTS
gctFORGIT_CHECKOUT_TAG_FZF_OPTS
gcoFORGIT_CHECKOUT_COMMIT_FZF_OPTS
grcFORGIT_REVERT_COMMIT_FZF_OPTS
gssFORGIT_STASH_FZF_OPTS
gspFORGIT_STASH_PUSH_FZF_OPTS
gcleanFORGIT_CLEAN_FZF_OPTS
grbFORGIT_REBASE_FZF_OPTS
gblFORGIT_BLAME_FZF_OPTS
gfuFORGIT_FIXUP_FZF_OPTS
gcpFORGIT_CHERRY_PICK_FZF_OPTS

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:

export FORGIT_STASH_FZF_OPTS='
--bind="ctrl-d:reload(git stash drop $(cut -d: -f1 <<<{}) 1>/dev/null && git stash list)"
'
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_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

📦 Optional dependencies

Completions

Bash

Zsh

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

💡 Tips

📃 License

MIT (c) Wenxuan Zhang