Git Fish Prompt

Joshua Crass
Jun 24, 2018 · 3 min read

Here’s how I set up my fish prompt helping me with git on the command line. Which is the only way to “git” things done. I hope you find this useful.

Below is the default fish prompt.

username@host ~/.c/fish> 

Out of the box, fish prompt is already awesome and it has so many more great features already built-in. Git command completion and git prompt support are just a couple of them. It’s all documented in the fish repo, but you need to know where to look. Now what I find very useful when working with git on the command line is setting up my prompt to show me the state of my current branch. Below we’ll look at my prompt and I’ll explain a little about each part.

First, we have our branch named “staging”. It is in the middle of a merge and our local branch is 4 commits ahead and 5 commits behind the upstream branch. Next we see 1 staged file, 2 conflicts, 3 un-staged changes and 4 untracked files. Hopefully you don’t find yourself in this situation too often. See more examples at the bottom.

Fish Prompt Config

Lets’s start by creating a fish prompt file using your preferred editor (i.e vi).

~/.config/fish/functions/fish_prompt.fish

Now you can paste in the code below and edit it as you see fit. Fish has default icons which you can see here. But those are kinda boring. So, I have chosen to use some much cooler emoji to help identify each status.

After saving fish_prompt.fish you will need to source the file or start a new shell or restart the terminal.

source ~/.config/fish/functions/fish_prompt.fish

⚠️ I found that sourcing the file did not always update my current prompt. I had to start a new shell. I noticed this specifically when playing around with show_informative_status

⚠️ Experiences with colors and emoji may vary based on platform, terminal, font sizing, font spacing and other circumstances. I’m running macOS, using iTerm2.

Alternatives and Examples

Show Upstream

Here we see a 🚧 3–1. This means the upstream branch has diverged and our local branch is ahead 3 and behind 1. This is different from above example, because we set __fish_git_prompt_showupstream to “verbose” from “informative”.

(staging 🚧  3-1| 👍 )

The “verbose” shows the number of commits ahead/behind (+/-) the upstream. The “informative” option is like verbose, but shows nothing when local is equal to the upstream. Also, it shows ahead and behind ☝️3 👇1 separately when diverged.

Informative Status

(staging |  💩 🚥  📦 🔍  🚧 2-3)

You can set some of the status options individually using the options below. Although you will need to remove or comment out show_informative_status. Also, that the layout is slightly different.

  • __fish_git_prompt_showstashstate
  • __fish_git_prompt_showdirtystate
  • __fish_git_prompt_showuntrackedfiles

Lots of options. Play around with these until you find the combination you like best. You can also view some other examples here on the fish-shell repo.

📚 Fish prompt documentation can be found here.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade