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.
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).
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.
fish_prompt.fish you will need to source the file or start a new shell or restart the terminal.
⚠️ 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
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.
(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.
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.