DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far...

Welcome! This is a Q&A website for computer programmers and users alike, focused on helping fellow programmers and users. Read more

What are you stuck on? Ask a question and hopefully somebody will be able to help you out!
+3 votes

zsh has a plugin for showing the active git branch in the command prompt when the current working directory is a git repository. It looks like $ full/repository/path :master >.
Can I have the same without zsh? My $TERM is rxvt-unicode-256color


2 Answers

0 votes
Best answer

You have to modify the PS1 variable. PS1 is the primary prompt string, read more here. You should find it defined in either /etc/bashrc or ~/.bashrc. Inside this file, create a new function that returns the current branch name

get_branch() {
    git branch 2> /dev/null | sed -e "/^[^*]/d" -e "s/* \(.*\)/\1/"

then simply append $(get_branch) to your PS1 string.

selected by
+1 vote

zPlus's answer is correct if you want only the branch name - this is the sort of thing you can find in many people's dotfiles collections - you can use mine if youd like a more informative prompt

edited by
Contributions licensed under CC0