Skip to content
Heechul Ryu edited this page Jan 28, 2023 · 33 revisions

Here's a collection of custom bindings you can easily add to your tigrc.

  • Move in diff view with arrow keys: bind diff <Up> move-up and bind diff <Down> move-down

  • Intent to add: bind status N !@git add -N %(file) (might be useful if you want to add-patch a newly created file)

  • Stage a single line: bind stage 1 stage-update-line

  • Interactive rebase: bind main B !git rebase -i %(commit)

  • Revert: bind main ! !git revert %(commit)

  • Create a new branch: bind refs n !@git branch "%(prompt Enter branch name: )"

  • Add/edit notes for the current commit used during a review: bind generic T !git notes edit %(commit)

  • less-like page scrolling: bind generic <Ctrl-f> scroll-page-down and bind generic <Ctrl-b> scroll-page-up

  • Add verbose flag to git-commit: bind generic C !git commit -v

  • Amend last commit: bind generic + !git commit --amend

  • Drop the selected stash: bind stash D !?git stash drop %(stash)

  • Apply the selected stash: bind stash A !?git stash apply %(stash)

  • Stash the unstaged changes: bind status S !?git stash save --keep-index %(prompt)

  • Delete a file: bind status D !@?rm %(file)

  • Tag the selected commit: bind main T !@git tag %(prompt) %(commit)

  • Push local changes to origin: bind status P !git push origin

  • Open the commit on Github: bind generic B @sh -c "xdg-open 'https://'$(git remote -v | grep -Eo 'github.com[:/][^.]+' | head -1 | tr : /)'/commit/%(commit)'"

  • Open the commit on any remote: bind generic o @sh -c "open 'https://'$(git remote -v | head -n1 | cut -f2 | sed 's|^https://||' | sed 's|^ssh://git@||' | sed 's|.git\ .*$||' | sed 's| .*$||')'/commit/%(commit)'"

  • Patch the file under the cursor: bind status P !git add --patch %(file)

  • Copy commit title to clipboard:

      bind generic 9 !@sh -c "git show -s --format=%s %(commit) | xclip -selection c" # Linux
      bind generic 9 !@sh -c "git show -s --format=%s %(commit) | pbcopy" # Mac
      bind generic 9 !@sh -c "git show -s --format=%s %(commit) > /dev/clipboard" # Cygwin
    
  • Add selected file to .gitignore and open vim for additional changes: bind status <Ctrl-r> !sh -c "echo %(file) >> .gitignore && vi .gitignore"

Comparing commits and files in external diff tool (e.g Beyond Compare)

  • Compare changed file in status view: bind status <F4> !sh -c "git difftool -y \"$(git rev-parse --show-toplevel)/%(file)\""

  • Compare selected commit in log view (main view) with its parent: bind main <F4> !git difftool -d %(commit)^!

  • Compare 2 different commits in log view - Select first commit, press F5, select second commit and press hotkey again: bind main <F5> @git tig-compare-commits %(commit) that requires the following alias in your .gitconfig:

      tig-compare-commits = "!f() { \
      	echo Checking branch existence; \
      	if [[ $(git branch --list temp-compare-base) != \"\" ]]; then\
      		echo Branch exists, comparing with $1; \
      		git difftool -d temp-compare-base..$1; \
      		git branch --delete temp-compare-base; \
      	else \
      		echo Creating initial branch at $1; \
      		git branch temp-compare-base $1; \
      	fi;\
      };"