Windows – How to configure git bash to display a timestamp for each command

bashgit-bashwindows 7

I run git's bash on Windows7 to manage source control for projects.

Can I edit C:\Program Files (x86)\Git\etc\git-prompt.sh to enable me to timestamp when I ran commands?

e.g.
instead of

user.name@machine /c/somedirectory
$ git pull origin develop
remote: Counting objects: 1, done.

Displaying

user.name@machine /c/somedirectory
$ git pull origin develop
21/04/2016 20:15:33
remote: Counting objects: 1, done.

So I can know whether something was run before/after a particular time.

Best Answer

This is solution to your problem, only difference from what you wrote, is that timestamp is displayed after the command output, and not before.

Under the Windows Program Files folder, open Git\etc\profile or Git\etc\profile.d\git-prompt.sh, search for lines which look like:

PS1="$PS1"'\n'                 # new line
PS1="$PS1"'\[\033[32m\]'       # change color
PS1="$PS1"'\u@\h '             # user@host<space>
PS1="$PS1"'\[\033[33m\]'       # change color
PS1="$PS1"'\w'                 # current working directory
if test -z "$WINELOADERNOEXEC"
then
    PS1="$PS1"'$(__git_ps1)'   # bash function
fi
PS1="$PS1"'\[\033[0m\]'        # change color
PS1="$PS1"'\n'                 # new line
PS1="$PS1"'$ '                 # prompt: always $

And add line

PS1="$PS1"' \t'                # time

before second-to-last line. That will give you prompt like:

user.name@machine /c/somedirectory 18:34:35
$ git pull origin develop
remote: Counting objects: 1, done.

user.name@machine /c/somedirectory 18:42:12
$

Here is list of other useful options you can add: http://makandracards.com/makandra/1090-customize-your-bash-prompt

Related Question