Top Related Projects
š A delightful community-driven (with 2,400+ contributors) framework for managing your zsh configuration. Includes 300+ optional plugins (rails, git, macOS, hub, docker, homebrew, node, php, python, etc), 140+ themes to spice up your morning, and an auto-update tool that makes it easy to keep up with the latest updates from the community.
A Zsh theme
The configuration framework for Zsh
šāØ Minimalistic, powerful and extremely customizable Zsh prompt
Pretty, minimal and fast ZSH prompt
āšļø The minimal, blazing-fast, and infinitely customizable prompt for any shell!
Quick Overview
Bash-git-prompt is a customizable Git prompt for Bash that provides enhanced information about the current Git repository status. It displays useful information such as the current branch, number of staged/modified/untracked files, and more, directly in your command prompt.
Pros
- Highly customizable with various themes and configuration options
- Provides detailed Git status information at a glance
- Supports both Bash and Zsh shells
- Actively maintained with regular updates and improvements
Cons
- May slow down terminal performance in large repositories
- Requires some initial setup and configuration
- Can be visually overwhelming for users who prefer minimal prompts
- Limited compatibility with some terminal emulators or custom shell configurations
Code Examples
- Basic usage (in
.bashrc
or.bash_profile
):
if [ -f "$HOME/.bash-git-prompt/gitprompt.sh" ]; then
GIT_PROMPT_ONLY_IN_REPO=1
source $HOME/.bash-git-prompt/gitprompt.sh
fi
- Customizing colors:
GIT_PROMPT_THEME_NAME="Custom"
GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}"
GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ "
GIT_PROMPT_STAGED="${Red}ā "
- Enabling/disabling specific features:
GIT_PROMPT_SHOW_UPSTREAM=1
GIT_PROMPT_SHOW_UNTRACKED_FILES=no
GIT_PROMPT_SHOW_CHANGED_FILES_COUNT=0
Getting Started
-
Clone the repository:
git clone https://github.com/magicmonty/bash-git-prompt.git ~/.bash-git-prompt --depth=1
-
Add the following to your
.bashrc
or.bash_profile
:if [ -f "$HOME/.bash-git-prompt/gitprompt.sh" ]; then GIT_PROMPT_ONLY_IN_REPO=1 source $HOME/.bash-git-prompt/gitprompt.sh fi
-
Restart your terminal or run
source ~/.bashrc
(or~/.bash_profile
) to apply changes. -
Customize the prompt by modifying the variables in your
.bashrc
or.bash_profile
as shown in the code examples above.
Competitor Comparisons
š A delightful community-driven (with 2,400+ contributors) framework for managing your zsh configuration. Includes 300+ optional plugins (rails, git, macOS, hub, docker, homebrew, node, php, python, etc), 140+ themes to spice up your morning, and an auto-update tool that makes it easy to keep up with the latest updates from the community.
Pros of Oh My Zsh
- More comprehensive and feature-rich, offering a wide range of plugins and themes
- Larger community and more frequent updates
- Includes productivity-enhancing features like auto-completion and syntax highlighting
Cons of Oh My Zsh
- Can be slower to load, especially with many plugins enabled
- More complex setup and configuration process
- Requires Zsh shell, which may not be the default on all systems
Code Comparison
bash-git-prompt:
GIT_PROMPT_ONLY_IN_REPO=1
source ~/.bash-git-prompt/gitprompt.sh
Oh My Zsh:
plugins=(git docker kubectl)
ZSH_THEME="robbyrussell"
source $ZSH/oh-my-zsh.sh
Summary
bash-git-prompt is a lightweight, focused tool for enhancing Git information in Bash prompts. It's easy to set up and doesn't require changing your shell.
Oh My Zsh is a comprehensive framework for Zsh that offers a wide range of features beyond Git integration. It provides a more customizable experience but requires switching to Zsh and may have a steeper learning curve.
Choose bash-git-prompt for a simple, Git-focused enhancement to your Bash prompt. Opt for Oh My Zsh if you want a full-featured shell environment with extensive customization options and are willing to switch to Zsh.
A Zsh theme
Pros of powerlevel10k
- Highly customizable with many built-in themes and options
- Faster performance, especially on slower systems
- Supports both Zsh and Bash shells
Cons of powerlevel10k
- More complex setup and configuration process
- Requires a Powerline-compatible font for full functionality
- May be overwhelming for users who prefer simplicity
Code Comparison
bash-git-prompt:
GIT_PROMPT_ONLY_IN_REPO=1
GIT_PROMPT_THEME=Default
source $HOME/.bash-git-prompt/gitprompt.sh
powerlevel10k:
source ~/powerlevel10k/powerlevel10k.zsh-theme
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs time)
Summary
bash-git-prompt is a simpler, more focused tool for enhancing Git information in Bash prompts. It's easier to set up and use but has fewer customization options. powerlevel10k offers a more comprehensive prompt customization experience with better performance, but it comes with a steeper learning curve and more complex configuration. The choice between the two depends on the user's shell preference, desired level of customization, and willingness to invest time in setup and configuration.
The configuration framework for Zsh
Pros of prezto
- Comprehensive Zsh configuration framework with modular design
- Extensive theming options and customizable prompts
- Includes many pre-configured modules for enhanced functionality
Cons of prezto
- Steeper learning curve due to its complexity
- Requires Zsh, not compatible with Bash
- May be overkill for users seeking a simple Git prompt
Code Comparison
bash-git-prompt:
if [ -f "$HOME/.bash-git-prompt/gitprompt.sh" ]; then
GIT_PROMPT_ONLY_IN_REPO=1
source $HOME/.bash-git-prompt/gitprompt.sh
fi
prezto:
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"
fi
Summary
bash-git-prompt is a lightweight, focused solution for adding Git information to your Bash prompt. It's easy to set up and use, making it ideal for users who primarily want Git status in their terminal.
prezto, on the other hand, is a comprehensive Zsh configuration framework that includes Git prompt functionality among many other features. It offers more customization options and additional modules but requires more setup and learning.
Choose bash-git-prompt for a simple Git-focused prompt in Bash, or prezto for a feature-rich Zsh environment with extensive customization options.
šāØ Minimalistic, powerful and extremely customizable Zsh prompt
Pros of spaceship-prompt
- More feature-rich with support for various programming languages and tools
- Highly customizable with easy configuration options
- Modern and visually appealing design with emoji support
Cons of spaceship-prompt
- Requires Zsh shell, limiting compatibility compared to bash-git-prompt
- May have a steeper learning curve for customization
- Potentially slower performance due to more complex features
Code Comparison
spaceship-prompt:
SPACESHIP_PROMPT_ORDER=(
user
dir
host
git
node
ruby
docker
# ...
)
bash-git-prompt:
GIT_PROMPT_ONLY_IN_REPO=1
GIT_PROMPT_THEME=Default
source $HOME/.bash-git-prompt/gitprompt.sh
spaceship-prompt offers a more extensive and flexible configuration, allowing users to easily customize the order and appearance of various prompt elements. bash-git-prompt, on the other hand, provides a simpler setup focused primarily on Git information in the prompt.
While spaceship-prompt is more feature-rich and visually appealing, bash-git-prompt is more lightweight and compatible with bash shells. The choice between the two depends on the user's specific needs, preferred shell, and desired level of customization.
Pretty, minimal and fast ZSH prompt
Pros of Pure
- Minimalist and clean design, focusing on essential information
- Asynchronous Git status updates for improved performance
- Customizable prompt symbol and colors
Cons of Pure
- Zsh-only, limiting its use to Zsh shell environments
- Requires additional setup and dependencies (e.g., zsh-async)
- May lack some advanced Git information provided by bash-git-prompt
Code Comparison
bash-git-prompt:
GIT_PROMPT_ONLY_IN_REPO=1
GIT_PROMPT_THEME=Default
source $HOME/.bash-git-prompt/gitprompt.sh
Pure:
autoload -U promptinit; promptinit
prompt pure
Key Differences
- bash-git-prompt is designed for Bash, while Pure is exclusively for Zsh
- bash-git-prompt offers more detailed Git information out-of-the-box
- Pure focuses on minimalism and performance, with a cleaner aesthetic
- bash-git-prompt has more theme options and customization features
- Pure leverages Zsh's powerful prompt system for easier integration
Both projects aim to enhance the command-line experience by providing informative and visually appealing prompts, but they cater to different shells and user preferences. The choice between them depends on the user's shell environment and desired balance between information density and simplicity.
āšļø The minimal, blazing-fast, and infinitely customizable prompt for any shell!
Pros of Starship
- Cross-shell compatibility (works with Bash, Zsh, Fish, and more)
- Highly customizable with a wide range of modules
- Written in Rust, offering better performance
Cons of Starship
- Requires Rust installation for setup
- More complex configuration process
- Potentially overwhelming with numerous options for new users
Code Comparison
bash-git-prompt:
GIT_PROMPT_ONLY_IN_REPO=1
source ~/.bash-git-prompt/gitprompt.sh
Starship:
# ~/.config/starship.toml
[git_branch]
symbol = "š± "
truncation_length = 4
truncation_symbol = ""
Summary
Starship offers a more feature-rich and customizable experience across multiple shells, while bash-git-prompt provides a simpler, Git-focused solution for Bash users. Starship's performance and extensive modules make it appealing for power users, but its setup complexity may deter some. bash-git-prompt is easier to set up and use out of the box, particularly for those primarily interested in Git information in their Bash prompt.
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
Informative git prompt for bash and fish
This prompt is a port of the "Informative git prompt for zsh" which you can find here
A bash
prompt that displays information about the current git repository.
In particular the branch name, difference with remote branch, number of files
staged, changed, etc.
gitstatus.sh
and git-prompt-help.sh
added by AKS.
Examples
The prompt may look like the following:
(masterĆ¢ĀĀ3|Ć¢ĀĀ1)
: on branchmaster
, ahead of remote by 3 commits, 1 file changed but not staged(status|Ć¢ĀĀ2)
: on branchstatus
, 2 files staged(master|Ć¢ĀĀ7â¦)
: on branchmaster
, 7 files changed, some files untracked(master|Ć¢ĀĀ2Ć¢ĀĀ3)
: on branchmaster
, 2 conflicts, 3 files changed(master|Ć¢ĀĀ2)
: on branchmaster
, 2 stash entries(experimentalĆ¢ĀĀ2Ć¢ĀĀ3|Ć¢ĀĀ)
: on branchexperimental
; your branch has diverged by 3 commits, remote by 2 commits; the repository is otherwise clean(:70c2952|Ć¢ĀĀ)
: not on any branch; parent commit has hash70c2952
; the repository is otherwise clean
Prompt Structure
By default, the general appearance of the prompt is::
(<branch> <upstream branch> <branch tracking>|<local status>)
The symbols are as follows:
- Local Status Symbols
Ć¢ĀĀ
: repository cleanĆ¢ĀĀn
: there aren
staged filesĆ¢ĀĀn
: there aren
files with merge conflictsĆ¢ĀĀ-n
: there aren
staged files waiting for removalĆ¢ĀĀn
: there aren
changed but unstaged filesâ¦n
: there aren
untracked filesĆ¢ĀĀn
: there aren
stash entries
- Upstream branch
- Shows the remote tracking branch
- Disabled by default
- Enable by setting
GIT_PROMPT_SHOW_UPSTREAM=1
- Branch Tracking Symbols
Ć¢ĀĀn
: ahead of remote byn
commitsĆ¢ĀĀn
: behind remote byn
commitsĆ¢ĀĀmĆ¢ĀĀn
: branches diverged, other bym
commits, yours byn
commitsL
: local branch, not remotely tracked
- Branch Symbol:
- When the branch name starts with a colon
:
, it means it's actually a hash, not a branch (although it should be pretty clear, unless you name your branches like hashes :-)
- When the branch name starts with a colon
Installation
via Homebrew on Mac OS X
-
Run
brew update
-
Run
brew install bash-git-prompt
for the last stable release orbrew install --HEAD bash-git-prompt
for the latest version directly from the repository -
Now you can source the file in your
~/.bash_profile
as follows:
if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then
__GIT_PROMPT_DIR=$(brew --prefix)/opt/bash-git-prompt/share
GIT_PROMPT_ONLY_IN_REPO=1
source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh"
fi
via Git clone
- Clone this repository to your home directory.
git clone https://github.com/magicmonty/bash-git-prompt.git ~/.bash-git-prompt --depth=1
Add to the ~/.bashrc
:
if [ -f "$HOME/.bash-git-prompt/gitprompt.sh" ]; then
GIT_PROMPT_ONLY_IN_REPO=1
source "$HOME/.bash-git-prompt/gitprompt.sh"
fi
install for the fish shell
-
If you cloned the repo to a directory other then
~/.bash-git-prompt
, set__GIT_PROMPT_DIR
in~/.config/fish/config.fish
to that path -
To install as an option in the fish_config GUI
sudo install -m 666 gitprompt.fish /usr/share/fish/tools/web_config/sample_prompts/
fish_config
Ā to install the bash-git-prompt as a choice under the prompt tab of the web config. Selecting this will copy it to
~/.config/fish/functions/fish_prompt.fish
- You can also do
mkdir -p ~/.config/fish/functions/
cp gitprompt.fish ~/.config/fish/functions/fish_prompt.fish
Ā to overwrite the current prompt with the bash-git-prompt directly
All configs for .bashrc
# Set config variables first
GIT_PROMPT_ONLY_IN_REPO=1
# GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status
# GIT_PROMPT_IGNORE_SUBMODULES=1 # uncomment to avoid searching for changed files in submodules
# GIT_PROMPT_WITH_VIRTUAL_ENV=0 # uncomment to avoid setting virtual environment infos for node/python/conda environments
# GIT_PROMPT_VIRTUAL_ENV_AFTER_PROMPT=1 # uncomment to place virtual environment infos between prompt and git status (instead of left to the prompt)
# GIT_PROMPT_SHOW_UPSTREAM=1 # uncomment to show upstream tracking branch
# GIT_PROMPT_SHOW_UNTRACKED_FILES=normal # can be no, normal or all; determines counting of untracked files
# GIT_PROMPT_SHOW_CHANGED_FILES_COUNT=0 # uncomment to avoid printing the number of changed files
# GIT_PROMPT_STATUS_COMMAND=gitstatus_pre-1.7.10.sh # uncomment to support Git older than 1.7.10
# GIT_PROMPT_START=... # uncomment for custom prompt start sequence
# GIT_PROMPT_END=... # uncomment for custom prompt end sequence
# as last entry source the gitprompt script
# GIT_PROMPT_THEME=Custom # use custom theme specified in file GIT_PROMPT_THEME_FILE (default ~/.git-prompt-colors.sh)
# GIT_PROMPT_THEME_FILE=~/.git-prompt-colors.sh
# GIT_PROMPT_THEME=Solarized # use theme optimized for solarized color scheme
source ~/.bash-git-prompt/gitprompt.sh
You can set the GIT_PROMPT_SHOW_UNTRACKED_FILES
variable to no
or normal
to speed things up if you have lots of
untracked files in your repository. This can be the case for build systems that put their build artifacts in
the subdirectory structure of the git repository. Setting it to all
will count all untracked files, including files
listed in .gitignore.
cd
to a git repository and test it!
Themes
The most settings are now stored in theme files. To select a theme, set the variable GIT_PROMPT_THEME
to the name
of the theme located in <INSTALLDIR>/themes
without the extension .bgptheme
like this:
GIT_PROMPT_THEME=Solarized
If you set GIT_PROMPT_THEME
to Custom
, then the .git-prompt-colors.sh
in the home directory will be used.
This file can now be generated with the command git_prompt_make_custom_theme [<Name of base theme>]
. If the name of
the base theme is ommitted or the theme file is not found, then the Default theme is used. If you have already a custom
.git-prompt-colors.sh
in your home directory, an error message will be shown.
You can display a list of available themes with git_prompt_list_themes
(the current theme is highlighted)
If you omit the GIT_PROMPT_THEME
variable, the Default theme is used or, if you have a custom .git-prompt-colors.sh
in your home directory, then the Custom theme is used.
Ubuntu Themes
Ubuntu requires a bit more spacing for some characters so it has its own themes.
These can be listed with git_prompt_list_themes
:
git_prompt_list_themes | grep Ubuntu
Theme structure
Please see the Custom.bgptemplate
in the themes
subdirectory of the installation directory!
A theme consists of a function override_git_prompt_colors()
which defines at least the variable GIT_PROMPT_THEME_NAME
with a unique theme identifier and a call to the function reload_git_prompt_colors <ThemeName>
like follows:
override_git_prompt_colors() {
GIT_PROMPT_THEME_NAME="Custom" # needed for reload optimization, should be unique
# Place your overrides here
...
}
# load the theme
reload_git_prompt_colors "Custom"
The advantage of this approach is, that you only need to specify the parts, that are different to the Default theme.
If you use a custom theme in .git-prompt-colors.sh
, please set GIT_PROMPT_THEME_NAME="Custom"
.
Further customizations
-
You can define
GIT_PROMPT_START
andGIT_PROMPT_END
to tweak your prompt. -
The default colors are defined within
prompt-colors.sh
, which is sourced bygitprompt.sh
. The colors used for various git status are defined inthemes/Default.bgptheme
. Both of these files may be overridden by copying them to $HOME with a.
prefix. They can also be placed in$HOME/lib
without the leading.
. The defaults are the original files in the~/.bash-git-prompt
directory. -
You can use
GIT_PROMPT_START_USER
,GIT_PROMPT_START_ROOT
,GIT_PROMPT_END_USER
andGIT_PROMPT_END_ROOT
in your.git-prompt-colors.sh
to tweak your prompt. You can also override the start and end of the prompt by settingGIT_PROMPT_START
andGIT_PROMPT_END
before you source thegitprompt.sh
. -
The current git repo information is obtained by the script
gitstatus.sh
. -
You can define
prompt_callback
function to tweak your prompt dynamically.
prompt_callback() {
if [ $(jobs | wc -l) -ne 0 ]; then
echo -n " jobs:\j"
fi
}
-
There are two helper functions that can be used within
prompt_callback
:gp_set_window_title <String>
- sets the window title to the given string (should work for XTerm type terminals like in OS X or Ubuntu)gp_truncate_pwd
- a function that returns the current PWD truncated to fit the current terminal width. Specify the length to truncate to as a parameter. Otherwise it defaults to 1/3 of the terminal width.
-
If you want to show the git prompt only if you are in a git repository you can set
GIT_PROMPT_ONLY_IN_REPO=1
before sourcing the gitprompt script -
You can show an abbreviated
username/repo
in the prompt by settingGIT_PROMPT_WITH_USERNAME_AND_REPO=1
and setting the placeholder_USERNAME_REPO_
in yourGIT_PROMPT_PREFIX
. You can also add aGIT_PROMPT_USERNAME_REPO_SEPARATOR=" | "
so theusername/repo
is nicely separated if there is a remote and if there is no remote, neither the username/repo part nor the separator will be shown. See the themeSingle_line_username_repo.bgptheme
for an example. -
There is an indicator at the start of the prompt, which shows the result of the last executed command by if you put the placeholder
_LAST_COMMAND_INDICATOR_
in any of the prompt templates. It is now by default activated in the default theme:
GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}"
GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}"
If you want to display the exit code too, you can use the placeholder
_LAST_COMMAND_STATE_
in GIT_PROMPT_COMMAND_OK
or GIT_PROMPT_COMMAND_FAIL
in your .git-prompt-colors.sh
:
GIT_PROMPT_COMMAND_OK="${Green}Ć¢ĀĀ " # displays as Ć¢ĀĀ
GIT_PROMPT_COMMAND_FAIL="${Red}Ć¢ĀĀ-_LAST_COMMAND_STATE_ " # displays as Ć¢ĀĀ-1 for exit code 1
-
It is now possible to disable the fetching of the remote repository either globally by setting
GIT_PROMPT_FETCH_REMOTE_STATUS=0
in your .bashrc or on a per repository basis by creating a file named.bash-git-rc
with the contentFETCH_REMOTE_STATUS=0
in the root of your git repository. -
You can also ignore a repository completely by creating a file named
.bash-git-rc
with the contentGIT_PROMPT_IGNORE=1
in the root of your git repository. -
If you have a repository with many untracked files, the git prompt can become very slow. You can disable the display of untracked files on a per repository basis by setting
GIT_PROMPT_SHOW_UNTRACKED_FILES=no
in your.bash-git-rc
in the repository or by disabling it globally in your.bashrc
-
If you have a repository with a deep submodule hierarchy, this can also affect performance. You can disable searching for changes in submodules on a per repository basis by setting
GIT_PROMPT_IGNORE_SUBMODULES=1
in your.bash-git-rc
-
You can get help on the git prompt with the function
git_prompt_help
. Examples are available withgit_prompt_examples
. A list of all available named colors is available withgit_prompt_color_samples
-
If you make any changes to any file that is sourced by
gitprompt.sh
, you should run this command, so that the next prompt update will find all the files and source them anew.
git_prompt_reset
- You can disable/enable gitprompt by running:
git_prompt_toggle
Enjoy!
Alternative RPM Install
This project ships an RPM spec to simplify installation on RHEL and clones. If you wish to install from RPM, you may first build the RPM from scratch by following this procedure:
- Clone this repository and tag the release with a version number
git tag -a -m "Tag release 1.1" 1.1
- Run the following command to create a tarball:
VER=$(git describe)
# replace dash with underscore to work around
# rpmbuild does not allow dash in version string
VER=${VER//\-/_}
git archive \
--format tar \
--prefix=bash-git-prompt-${VER}/ \
HEAD \
-- *.sh \
*.fish \
LICENSE.txt \
README.md \
themes \
> bash-git-prompt-${VER}.tar
mkdir -p /tmp/bash-git-prompt-${VER}
sed "s/Version:.*/Version: ${VER}/" \
bash-git-prompt.spec \
> /tmp/bash-git-prompt-${VER}/bash-git-prompt.spec
OLDDIR=$(pwd)
cd /tmp
tar -uf ${OLDDIR}/bash-git-prompt-${VER}.tar \
bash-git-prompt-${VER}/bash-git-prompt.spec
cd ${OLDDIR}
gzip bash-git-prompt-${VER}.tar
mv bash-git-prompt-${VER}.tar.gz bash-git-prompt-${VER}.tgz
- Log into an RHEL or clones host and run:
rpmbuild -ta bash-git-prompt-xxx.tar.gz
Then you may publish or install the rpm from "~/rpmbuild/RPMS/noarch".
License
This code is under the BSD 2 Clause (NetBSD) license.
Who Are You?
The current maintainer of the original bash-git-prompt is Martin Gondermann.
Contributing
If you want to contribute you can look for issues with the label up-for-grabs. Please leave a comment on the issue, that you want to fix it, so others know, the labels are "taken".
Pull requests are welcome. I will check them and merge them, if I think they help the project.
Similar projects
Donations
I accept tips through Flattr.
Top Related Projects
š A delightful community-driven (with 2,400+ contributors) framework for managing your zsh configuration. Includes 300+ optional plugins (rails, git, macOS, hub, docker, homebrew, node, php, python, etc), 140+ themes to spice up your morning, and an auto-update tool that makes it easy to keep up with the latest updates from the community.
A Zsh theme
The configuration framework for Zsh
šāØ Minimalistic, powerful and extremely customizable Zsh prompt
Pretty, minimal and fast ZSH prompt
āšļø The minimal, blazing-fast, and infinitely customizable prompt for any shell!
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