Tuesday, July 23, 2024
HomeDeveloperCurrent Git branch name in command prompt

Current Git branch name in command prompt

Date:

Related stories

Play Crazy Time and Win Big

Crazy Time is an exciting live casino game that...

Starzbet APP: Features and User Experience

In the rapidly evolving landscape of online betting, accessibility...

Hassle-Free Starzbet Giriş: Start Betting Instantly

Starzbet Giriş, or login, is your gateway to a...

Get the Latest Updates on Starzbet Twitter

In the fast-paced world of online gaming and betting,...

Starzbet Güncel Giriş: Your Key to Winning

In the ever-evolving landscape of online betting, staying ahead...
spot_img
Since we started using Git branches as part of our dev workflow at work, it has become essential to always be sure that you’re working with the right branch. You can either always check git branch, or let the current branch name be displayed as part of the command line all the time when you’re inside a Git project. This is very convenient and helps you not to mess the things up.

There are several ways how to output the git branch name to the command line, and I’ll share the one I use and worked fine on all machines where I have tested it. I have originally found it on DeveloperZen.

If you’re working in Linux (I have tested with Ubuntu), just add the following code to .bashrc file in your home directory:

function parse_git_branch () {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
 
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NO_COLOR="\[\033[0m\]"
 
PS1="$GREEN\u@\h$NO_COLOR:\w$YELLOW\$(parse_git_branch)$NO_COLOR\$ "

If you’re on Mac, you should put this code to .bash_profile in your home directory. For Windows you probably won’t need this because the “Git for Windows” command line interface handles this functionality by default.

The function parse_git_branch() could be replaced with predefined __git_ps1() normally available in bash, but this one didn’t work well on one of my colleagues computer (it did show the “master” branch name all the time, even if not in a git project). This snippet also adds some colors to your command prompt. How cool is that? 🙂

Latest stories

spot_img
https://swi.sch.id/
https://zad.sch.id/
https://maruda.jp/
https://stikesserulingmas.ac.id/uploads/sv/
https://stikesserulingmas.ac.id/js/xhitam/
https://stikesserulingmas.ac.id/wp-content/js/sbo/
https://www.almuniroh.com/
sabung ayam online
slot mahjong
akun pro jepang
TANGKASNET/
AKUN PRO PLATINUM
https://rajawalitanjungsari.com
sv388
casino online
agen sbobet
sabung ayam online
mahjong ways 2
scatter hitam
slot thailand
slot thailand
indobola77
indobola77
sabung ayam online
slot777
slot gacor
indomax88
indomax88
slot gacor
bandar303
bandar303
bandar303
Juara303
indobit88
master303 slot
master303 slot
Scatter Hitam
sabung ayam online
slot gacor
bola gacor
akun pro thailand
Sabung Ayam Online
Slot777
Ws168
https://sma1polanharjo.sch.id/
Casino Online
https://realcount-bundaenie.com/
https://operator-bsnpgkotabekasi.com/
https://vca.sch.id/core/assets/vgacor/
https://bsnpgkotabekasi.com/
slot thailand
sv388
sabung ayam online
sv388
sabung ayam online
slot gacor
slot zeus
slot gacor
sv388
https://ela.p3tik.unisma.ac.id/
sbobet
sv388
sbobet
Zeus Slot
Akun Jp
Zeus Slot
Slot Thailand
Scatter Hitam
Slot777
Sv388
Akun Demo Slot
Education School