How can I configure git bash to display a timestamp for each command?

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.


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


Win10 git-bash: C:\Program Files\Git\etc\profile.d

PS1="$PS1"'\[\033[0m\]'        # change color
PS1="$PS1"' \D{%F %T}'         # time in ISO8601 format ←
PS1="$PS1"'\n'                 # new line
PS1="$PS1"'$ '                 # prompt: always $

\D{format}

   the format is passed to strftime(3)  and  the  result  is
   inserted  into the prompt string; an empty format results
   in a locale-specific time representation.  The braces are
   required

References

https://stackoverflow.com/questions/13001902/how-to-configure-git-bash-prompt-by-adding-datetime

https://bneijt.nl/blog/post/add-a-timestamp-to-your-bash-prompt/