Modify RStudio prompt to show current git branch

Tags : tips, development, rstudio
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 !!

About the author

Sébastien Rochette

Sébastien Rochette

Modélisateur, formateur R, joueur de cartographies

One response to “Modify RStudio prompt to show current git branch”

  1. Thanks for the post!
    In the last release of {prompt} (1.0.0) memuse() has been replaced by mem()
    prompt::mem() should replace prompt::memuse() otherwise you get an error at startup.

    The additional package is not {memuse} anymore but {ps}

Leave a Reply

Also read