---
title: "How to show the git branch in the terminal"
date: "2022-02-09"
slug: "how-to-show-the-git-branch-in-the-terminal"
author: "Dany Paredes"
canonical: "https://danywalls.com/how-to-show-the-git-branch-in-the-terminal"
description: "I'm a git Kraken lover but sometimes surf into my projects. I love to know in which branch I'm working. Edit the .bash_profile and paste the following lines. parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \\(.*\\)/ (\\1)/' ..."
---

I'm a git Kraken lover but sometimes surf into my projects. I love to know in which branch I'm working.

Edit the .bash_profile and paste the following lines.

```bash
parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\[\033[32m\]\w - \$(parse_git_branch)\[\033[00m\] $ "
```

![Terminal with branch name](/images/posts/how-to-show-the-git-branch-in-the-terminal/cLx5VyM4i_10081.png)

> If you are using zsh 

```bash
function parse_git_branch() {
    git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
export PROMPT='%~ $(parse_git_branch) $ '
```

Have a nice day :)

