Groesbeek, view of the 'National Liberation Museum 1944-1945' in Groesbeek. © Ton Kersten
Fork me on GitHub
Posts tagged as git

git status in the prompt

2012-07-23 (124) by Ton Kersten, tagged as code, git, linux, sysadm

Working with git a lot I decided I needed some git status in my prompt.

I searched the web and some solutions where almost what I wanted and this one by Sebastian Celis came very close.

But it didn't work with my version of zsh, because that didn't seem to understand the =~ operator.

I also think Sebastian makes things over complicated and so I changed some things aroud.

This is what I came up with:

First make sure this code is included in your ~/.zshenv file

    unset __GIT_BRANCH
    unset __GIT_BRANCH_DIRTY

    local st="$(git status 2>/dev/null)"
    if [[ -n "$st" ]]; then
        local -a arr

        if [[ $arr[1] = *Not\ currently\ on\ any\ branch.* ]]

        if [[ $arr[2] = *Your\ branch\ is* ]]
            if [[ $arr[2] = *ahead* ]]
            elif [[ $arr[2] = *diverged* ]]

        if [[ $st = *nothing\ to\ commit* ]]

    if [[ -n "$__GIT_BRANCH" ]]
        local s="("
        case "$__GIT_BRANCH_STATUS"
            ahead)      s+="↑"  ;;
            diverged)   s+="↕"  ;;
            behind)     s+="↓"  ;;
        if [[ "$__GIT_BRANCH_DIRTY" = "1" ]]

        printf " %s%s" "%{${fg[yellow]}%}" $s

and set your prompt to something like this

PS1=$'$C_CYAN%n@%m$(prompt_git_info) $C_WHITE%2~$ $C_OFF'

When I now switch to a directory that is under control of git I get gt status messages in my prompt, like

tonk@mach (master) ~/dir$ git commit -a
[master fca5ac3] Nice, new stuff.
 6 files changed, 88 insertions(+), 12 deletions(-)
tonk@mach (master) ~/.dir$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
nothing to commit (working directory clean)
tonk@mach (master) ~/.dir$

New version of

2010-12-20 (84) by Ton Kersten, tagged as git

I was working on a customers project and I had to change a lot of files. This could easily be done with the sed and find commands, but I wanted these changes to be checked in into git as well. And I also wanted the git keywords expanded.

There was always the trick to edit all the files with sed, then edit them again with and just press ZZ for all files. This would be tedious, I know.

So I decided to take the Geeks Shortcut and recode so everything can be be done automatic.

Read more »


2010-11-09 (77) by Ton Kersten, tagged as git

It took some time, but I did manage to make a new version of It has some errors corrected and some extra features.

And now it comes with its own, shiny, new man page. (

Come and g[ei]t it. It's in the files section or on github.

Or clone it with:

git clone

I'm on Github

2010-10-04 (72) by Ton Kersten, tagged as git

As I develop some scripts and other things for fun I decided to make some of these more public.

The following projects can be found on Github, with this URL.

  • Header
  • MySQL backup

Have fun ans let me know what you think.

No more git RPM's

2010-08-30 (69) by Ton Kersten, tagged as git

I, for some time now, created RPM's for git. I will not do that anymore, because Dag Wieers RPMForge now has them and even up-to-date ones as well.

I also removed the git archive RPM's.

New Git RPM set

2010-07-20 (53) by Ton Kersten, tagged as git

There is a complete new set of Git RPMs put online. This is version and they are compiled for CentOS 5.5 on the i386 architecture.

You can find them in the Downloads section.

Those busy git developers

2010-03-25 (47) by Ton Kersten, tagged as git

Last time I blogged that the developers of git are a really busy bunch.

Well, they really are. I found out I almost missed a complete release, so with this set I'm catching up.

Today I build version

By now, you know where to find them.

The next entry will be more interresting, not only git building.

Those busy git developers

2010-03-13 (46) by Ton Kersten, tagged as git

The developers of git are a really busy bunch. Today a new git ( arrived, again, so I did build the RPM's.

By now, you know where to find them.