Convert Figma logo to code with AI

nvie logogit-toolbelt

A suite of useful Git commands that aid with scripting or every day command line usage

1,299
113
1,299
10

Top Related Projects

An informative and fancy bash prompt for Git users

GIT utilities -- repo summary, repl, changelog population, author commit percentages and more

21,631

Most commonly used git tips and tricks.

Good-lookin' diffs. Actually… nah… The best-lookin' diffs. :tada:

62,551

simple terminal UI for git commands

An interactive way to peruse your git history from the terminal

Quick Overview

Git-toolbelt is a collection of shell scripts that enhance Git functionality and workflow. It provides additional commands and utilities to simplify common Git operations, improve productivity, and offer insights into repository status.

Pros

  • Extends Git with useful commands not available in standard Git
  • Improves productivity by simplifying complex Git operations
  • Easily integrates with existing Git workflows
  • Customizable and extensible for specific needs

Cons

  • Requires separate installation and setup
  • May introduce dependencies on non-standard Git commands
  • Learning curve for new users unfamiliar with the additional commands
  • Potential compatibility issues with different Git versions or environments

Getting Started

To get started with git-toolbelt:

  1. Clone the repository:

    git clone https://github.com/nvie/git-toolbelt.git
    
  2. Add the bin directory to your PATH:

    export PATH="/path/to/git-toolbelt/bin:$PATH"
    
  3. Make sure the scripts are executable:

    chmod +x /path/to/git-toolbelt/bin/*
    
  4. Start using the new commands, for example:

    git recent
    git cleanup
    git modified
    

Note: It's recommended to review the scripts and their functionality before using them in your workflow.

Competitor Comparisons

An informative and fancy bash prompt for Git users

Pros of bash-git-prompt

  • Provides a highly customizable and informative Git prompt in Bash
  • Displays real-time Git status information directly in the command line
  • Supports themes and extensive configuration options

Cons of bash-git-prompt

  • Limited to Bash shell environments
  • May slow down terminal performance in large repositories
  • Requires additional setup and configuration

Code Comparison

bash-git-prompt:

GIT_PROMPT_ONLY_IN_REPO=1
GIT_PROMPT_THEME=Default
source $HOME/.bash-git-prompt/gitprompt.sh

git-toolbelt:

alias gt='git-toolbelt'
gt branch-clean-local
gt recent-branches

Summary

bash-git-prompt focuses on enhancing the command line prompt with Git information, while git-toolbelt provides a collection of Git utility scripts. bash-git-prompt offers a more visual and immediate representation of Git status, but is limited to Bash environments. git-toolbelt, on the other hand, offers a wider range of Git-related tools that can be used across different shells and environments, but doesn't modify the prompt itself.

Both projects aim to improve Git workflows, but they approach this goal from different angles. bash-git-prompt is ideal for users who want constant visibility of their Git status, while git-toolbelt is better suited for those who prefer a set of powerful Git commands to streamline their workflow.

GIT utilities -- repo summary, repl, changelog population, author commit percentages and more

Pros of git-extras

  • Larger collection of commands (over 70) covering a wide range of Git operations
  • Active development with frequent updates and contributions
  • Includes some unique features like git undo, git ignore-io, and git delta

Cons of git-extras

  • May include commands that overlap with built-in Git functionality
  • Some commands might be less intuitive or require additional learning
  • Installation process can be more complex depending on the operating system

Code comparison

git-extras:

git summary
git effort --above 50
git fork
git release 1.5.0

git-toolbelt:

git recent
git recent-branches
git cleanup
git push-current

Key differences

  • git-extras focuses on providing a comprehensive set of additional Git commands
  • git-toolbelt emphasizes simplicity and enhancing existing Git workflows
  • git-extras has a larger community and more frequent updates
  • git-toolbelt offers a more curated set of commands with a focus on productivity

Both projects aim to extend Git functionality, but git-extras provides a broader range of tools, while git-toolbelt focuses on streamlining common Git operations.

21,631

Most commonly used git tips and tricks.

Pros of git-tips

  • Extensive collection of Git tips and tricks covering a wide range of scenarios
  • Community-driven project with contributions from many users
  • Regularly updated with new tips and improvements

Cons of git-tips

  • Lacks custom scripts or tools; primarily a collection of Git commands
  • May require more manual effort to implement tips compared to ready-made scripts
  • No standardized testing or validation of tips

Code comparison

git-tips:

git log --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=short

git-toolbelt:

#!/bin/sh
set -eu
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative "$@"

The git-tips example shows a single command for customized log output, while git-toolbelt provides a script with error handling and additional options.

git-toolbelt offers a curated set of custom Git scripts and commands, focusing on enhancing Git workflows with ready-to-use tools. It provides a more structured approach with tested scripts, but may have a narrower scope compared to the extensive collection of tips in git-tips.

Good-lookin' diffs. Actually… nah… The best-lookin' diffs. :tada:

Pros of diff-so-fancy

  • Focuses specifically on enhancing Git diff output, providing a more visually appealing and readable format
  • Offers syntax highlighting and word-level diffs, making changes easier to identify
  • Lightweight and easy to install, with minimal configuration required

Cons of diff-so-fancy

  • Limited in scope compared to git-toolbelt, which offers a broader range of Git utilities
  • May require additional setup for integration with certain Git GUI clients
  • Doesn't provide additional Git workflow improvements beyond diff enhancement

Code comparison

diff-so-fancy:

git diff --color | diff-so-fancy

git-toolbelt:

git recent
git recent-branches
git cleanup

Summary

diff-so-fancy excels at improving Git diff readability but has a narrower focus. git-toolbelt offers a more comprehensive set of Git utilities, enhancing various aspects of Git workflows. While diff-so-fancy is ideal for users primarily interested in better diff visualization, git-toolbelt provides a broader toolkit for Git power users.

62,551

simple terminal UI for git commands

Pros of lazygit

  • Interactive TUI interface for easier Git operations
  • Comprehensive view of repository status, branches, and commits
  • Built-in diff viewer and commit staging capabilities

Cons of lazygit

  • Steeper learning curve for users accustomed to command-line Git
  • Requires terminal with specific capabilities (e.g., color support)
  • May be overkill for simple Git operations

Code comparison

lazygit (main.go):

func main() {
    app := app.NewApp(config.AppConfig)
    app.Run()
}

git-toolbelt (git-recent-branches):

#!/bin/sh
git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short)' |
    grep -v '^\*' |
    head -n 15

Key differences

  • lazygit is a full-featured TUI application written in Go
  • git-toolbelt is a collection of shell scripts for specific Git tasks
  • lazygit offers a more visual and interactive experience
  • git-toolbelt provides lightweight, focused tools for command-line users

Use cases

  • lazygit: Ideal for users who prefer a visual interface and want a comprehensive Git management tool
  • git-toolbelt: Better suited for command-line enthusiasts and those who need quick, specific Git utilities

Both projects aim to enhance Git workflows, but they cater to different user preferences and needs.

An interactive way to peruse your git history from the terminal

Pros of git-recall

  • Focused on a single, specific task: visualizing git history
  • Simple and intuitive command-line interface
  • Customizable output format with various options

Cons of git-recall

  • Limited functionality compared to git-toolbelt's broader set of tools
  • Less actively maintained (fewer recent updates)
  • Lacks some advanced features for complex git workflows

Code comparison

git-recall:

git recall
git recall --author="John Doe" --since="1 week ago"

git-toolbelt:

git-recent
git-recent-branches
git-cleanup

Key differences

git-recall is a specialized tool for visualizing git history, while git-toolbelt is a collection of various git utilities. git-recall offers a more focused and user-friendly approach to reviewing commit history, whereas git-toolbelt provides a broader range of functionality for different git-related tasks.

git-toolbelt includes features like branch management, repository cleanup, and advanced diff tools, making it more suitable for users who need a comprehensive set of git utilities. On the other hand, git-recall excels at its primary function of displaying commit history in a clear and customizable manner.

Both projects are open-source and can be easily integrated into existing git workflows, but users should choose based on their specific needs and preferences for git history visualization versus a more extensive toolkit.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

git-toolbelt logo

Installation instructions

$ brew tap nvie/tap
$ brew install nvie/tap/git-toolbelt

If not using Homebrew, you will need to have GNU coreutils installed, for the realpath utility. Git for Windows users see #29.

git-toolbelt

Helper tools to make everyday life with Git much easier. Commands marked with ⭐️ are my personal favorites and are commands I use almost every day.

Everyday helpful commands:

Statistics:

Commands to help novices out:

Commands that simplify scripting. These commands typically only return exit codes and have no output.

Advanced usage:

git current-branch

Returns the name of the current branch, if any. Why doesn't this come with git?

$ git current-branch
master

Alias to git rev-parse --abbrev-ref HEAD.

git main-branch

Returns the name of the default main branch for this repository. Historically master, but could also be main if you've changed the default branch name. Since there's no way of reliably telling what the default branch name is for a repo, this script will probe for the existence of local branches named either main or master. The first one found is used.

$ git main-branch
master

git sha

Returns the SHA value for the specified object, or the current branch head, if nothing is provided.

$ git sha <some-object>

Typical example:

$ git sha HEAD
f688d7543c5d52f5f78b3db1b0dd1616059299a4
$ git sha -s HEAD
f688d75

Shows the commit SHA for the latest commit.

git modified

Returns a list of locally modified files. In contrast to git status, it does not include any detailed file status, and never includes non-existing files.

This makes it ideal for the following use-case:

$ vim (git modified)

If you want to locally modified files that are already staged, too, use:

$ vim (git modified -i)

git modified-since

Like git-modified, but for printing a list of files that have been modified since master (or whatever commit specified). In contrast to git status, it does not include any detailed file status, and never includes non-existing files.

Opens all files modified on your branch (since you branched off master).

$ vim (git modified-since)

git separator

Adds a commit with a message of only ---'s, so that it visually separates commits in the history. This is incredibly useful when doing more complex rebase operations. (They should be used as a temporary measure, and ideally taken out of the history again when done rebasing.)

git spinoff

Inspired by Magit's spinoff command. Creates and checks out a new branch starting at and tracking the current branch. That branch in turn is reset to the last commit it shares with its upstream. If the current branch has no upstream or no unpushed commits, then the new branch is created anyway and the previously current branch is not touched.

This is useful to create a feature branch after work has already began on the old branch (likely but not necessarily "master").

git push-current

Pushed the current branch out to origin, and makes sure to setup tracking of the remote branch. Shorthand for git push -u origin <current-branch>.

Accepts options, too, so you can use

$ git push-current -f

to force-push.

git is-headless

Tests if HEAD is pointing to a branch head, or is detached.

git diff-since

Shows the differences made on the current branch, compared to the main branch (or the given branch).

git local-branches / git remote-branches / git active-branches

Returns a list of local or remote branches, but contrary to Git's default commands for this, returns them machine-processable. In the case of remote branches, can be asked to return only the branches in a specific remote.

For git active-branches, a branch is deemed "active" if its head points to a commit authored in the last 3 weeks, by default. An arbitrary date can be specified using either git active-branches -s <date> or -a <date> (mnemonic: "since" or "after"), using any date format supported by git log.

git local-branch-exists / git remote-branch-exists / git tag-exists

Tests if the given local branch, remote branch, or tag exists.

git recent-branches

Returns a list of local branches, ordered by recency:

$ git recent-branches
foo
master
bar
qux

git remote-tracking-branch

Print the name of the remote tracking branch of the current or given local branch name, if one exists. Errors otherwise.

git local-commits / git has-local-commits

Returns a list of commits that are still in your local repo, but haven't been pushed to origin. git has-local-commits is the scriptable equivalent that only returns an exit code if such commits exist.

git contains / git is-ancestor

Tests if X is merged into Y:

$ git contains X Y  # does X contain Y?
$ git is-ancestor X Y  # is X an ancestor of Y?

CAVEAT: Even though they might look like opposites, X contains Y does not mean not (X is-ancestor Y), since (1) X and Y can point to the same commit, or the branches may have no common history and thus be unrelated completely.

git stage-all

Mimics the index / staging area to match the working tree exactly. Adds files, removes files, etc.

Alias to git add --all.

git unstage-all

Unstages everything. Leaves the working tree intact.

Alias to git reset HEAD.

git undo-merge

Ever created a merge accidentally, or decided that you didn't want to merge after all? You can undo the last merge using git undo-merge.

git undo-commit

Ever committed too soon, or by accident? Or on the wrong branch? You can now undo your last commit and you won't lose any data. All the changes in the commit will be staged (like right before the commit) and the commit itself is gone.

git cleanup

Deletes all branches that have already been merged into the main branch. Keeps other branches lying around. Removes branches both locally and in the origin remote. Will be most conservative with deletions.

git fixup

Amend all local staged changes into the last commit. Ideal for fixing typo's, when you don't want to re-edit the commit message.

$ git commit -m "Something cool."
$ vim somefile.txt  # fix typo
$ git add somefile.txt
$ git fixup  # merge this little change back into the last commit

git fixup-with

Interactively lets you pick a commit to fixup with. (Uses fzf for the interactive picking. Use brew install fzf to install this tool separately.) Use -r to trigger an interactive rebase right afterwards.

git workon

Convenience command for quickly switching to a branch <name>. If such local branch does not exist, but there is a remote branch named origin/<name>, then a local branch is created and the remote is tracked.

git delouse

Say you want to rebuild your last commit, but want to keep the commit message. git delouse empties the last commit on the current branch and places all changes back into the working tree.

Since the commit remains in history, you can now rebuild the commit by "git amend"'ing or "git fixup"'ing, instead of making new commits.

git shatter-by-file

Splits the last commit into N+1 commits, where N is the number of files in the last commit. The first commit is an empty commit with the original commit message and author details, and the following commits add (or delete) one file each, keeping the subject line of the original commit message.

After running git shatter-by-file, you'll typically want to run git rebase --interactive to start fixing up changes to files, etc. For that purpose, the original commit message is kept in there (in the empty first commit), so make sure to use it.

git cleave

Splits the last commit into 2 or more commits. Takes one or more regex values (which are fed to grep -Ee), and will split the last commit by file paths matching each of the regexes.

For example:

$ git cleave client/ server/

Will split the last commit into 2 (or 3) commits. The first one will contain all the files containing client/, the second will contain all the files matching server/. If there are files that don't match either of those, then a 3rd commit will be made with the "remainder".

Another example:

$ git cleave '.*\.js$'

This will split off all Javascript files from a commit.

git commit-to

Ever been on a branch and really wanted to quickly commit a change to a different branch? Given that this is possible without merge conflicts, git commit-to will allow you to do so, without checking out the branch necessarily.

$ git branch
  master
* mybranch
$ git status
M foo.txt
M bar.txt
$ git add foo.txt
$ git commit-to master -m "Add foo to master."
$ git add bar.txt
$ git commit -m "Add bar to mybranch."

git cherry-pick-to

Every been on a branch, just made a commit, but really want that commit available on other branches as well? You can now cherry-pick this commit to any branch, staying on the current branch. (Given the change won't lead to a merge conflict.)

$ git branch
  master
* mybranch
$ git add foo.txt
$ git commit -m "Really useful thing."
$ git cherry-pick-to master HEAD
$ git branch  # did not switch branches
  master
* mybranch

git is-repo

Helper function that determines whether the current directory has a Git repo associated to it. Scriptable equivalent of git repo.

git root / git repo

git root prints the root location of the working tree.

$ cd /path/to/worktree
$ cd some/dir/in/worktree
$ pwd
/path/to/worktree/some/project/dir
$ git root
/path/to/worktree

git repo prints the location of the Git directory, typically .git, but could differ based on your setup. Will return with a non-zero exit code if not in a repo.

$ cd /path/to/my/worktree
$ git repo
.git
$ cd /tmp
$ git repo
fatal: Not a git repository (or any of the parent directories): .git

git initial-commit

git initial-commit prints the initial commit for the repo.

$ git initial-commit
48c94a6a29e9e52ab63ce0fab578101ddc56a04f

git has-local-changes / git is-clean / git is-dirty

Helper function that determines whether there are local changes in the working tree, by returning a 0 (local changes) or 1 (no local changes) exit code.

git drop-local-changes

Don't care about your local working copy's state and really want to revert back to whatever is recorded in the history? git drop-local-changes lets you do this.

This covers aborting rebases, undoing partial merges, resetting the index and removing any unknown local files from the work tree. Anything that is already committed remains safe.

??? issue a git pull, too? Typical beginners will want this.

git stash-everything

The stash behaviour you (probably) always wanted. This actually stashes everything what's in your index, in your working tree, and even stashes away your untracked files, leaving a totally clean working tree.

Using "git stash pop" will recover all changes, including index state, locally modified files, and untracked files.

git update-all

Updates all local branch heads to the remote's equivalent. This is the same as checking out all local branches one-by-one and pulling the latest upstream changes. Will only update if a pull succeeds cleanly (i.e. is a fast-forward pull).

git-merged / git-unmerged / git-merge-status

This trio of subcommands makes it easy to inspect merge status of local branches. Use them to check whether any local branches have or haven't been merged into the target branch (defaults to master).

git-merge-status is a useful command that presents both lists in a single overview (not for machine processing).

git-branches-containing

This command, "git branches-containing []" returns a list of branches which contain the specified '' (defaults to 'HEAD').

git-branches-containing is useful to see if a branch has been merged, and, if so, which releases contain the feature/fix (if you use release branches).

git-committer-info

Shows contribution stats for the given committer, like "most productive day", "most productive hour", "average commit size", etc.

TODO: git force-checkout

Don't care about your local working copy's state and really want to switch to another branch? git force-checkout lets you do this.

Switching branches can be prevented by git. For good reasons, mostly. Git is designed to prevent you from losing data potentially. Examples are there are local unmerged files, or some files that would be overwritten by doing the checkout.

By using force-checkout you basically give git the finger, and check out a branch anyway. You do agree to lose data when using this command.

$ git checkout master
error: Your local changes to the following files would be overwritten by checkout:
    foo/bar.txt
Please, commit your changes or stash them before you can switch branches.
Aborting
$ git force-checkout master
Switched to branch 'master'

git conflicts

Generates a summary for all local branches that will merge uncleanly—i.e. will lead to merge conflicts later on.

$ git branch
  develop
* mybranch
  master
  other-branch
$ git conflicts
develop... merges cleanly
master...  merges cleanly
other-branch... CONFLICTS AHEAD

git-skip / git-unskip / git-show-skipped

Git supports marking files "skip worktree", meaning any change in the file locally will not be shown in status reports, or be added when you stage all files. This feature can be useful to toggle some switches locally, or experiment with different settings, without running the risk of accidentally committing this local data (that should remain untouched in the repo).

Notice that status reports won't show these files anymore, so it's also easily to lose track of these marked assumptions, and you probably run into weird issues if you don't remember this. (This is the reason why I put these scripts in the "advanced" category.)

Basic usage:

$ git status
 M foo.txt
 M bar.txt
 M qux.txt
$ git skip foo.txt
$ git status
 M bar.txt
 M qux.txt
$ git show-skipped
foo.txt
$ git commit -am 'Commit everything.'
$ git status
nothing to commit, working directory clean
$ git is-clean && echo "clean" || echo "not clean"
not clean
$ git unskip -a
$ git status
 M foo.txt

As you can see, git-is-clean is aware of any lurking "skipped" files, and won't report a clean working tree, as these assumed unchanged files often block the ability to check out different branches.

git wip

Commits all local changes under a commit message of "WIP". Great for quickly creating "savepoint" commits. If there is a mix of staged changes, and unstaged changes, and new files, will commit each of these as a separate commit, all titled "WIP". Effectively, running git-wip once will potentially lead to anywhere between 0 and 3 "WIP" commits being created.