Modify RStudio prompt to show current git branch

Author : Sébastien Rochette
Categories : tips, development, rstudio
Tags :
Date :

At the last Raddicts Paris Meetup, Romain Francois (to be followed on twitter here) made one strong impression, among others, with his RStudio console which indicates the active git branch and the RAM memory used by R.

If you too want to have this (to shine in society or because you spend your time doing git checkout):

git info shown in R console prompt in RStudio


Here is the way to go:

This code to show the active git branch and R memory used needs to be hosted in your ".Rprofile"

  • You first need to install package {prompt} from Gabor Csardi. This package is not on CRAN, you will need to install it from GitHub using:
  • Dependencies may not be directly installed and you will need to additionally install package {memuse}:
  • Then, open your ".Rprofile", using {usethis}
  • The content of your ".Rprofile" is executed as soon as you start R. Add the following code in this file:
"[", prompt::git_branch(), prompt::git_dirty(), prompt::git_arrows(), "] ",

Tada !

Thanks Romain !!


Also read