Show Git branch name in Shell prompt

Source: Internet
Author: User
Tags using git

| Introduction If you are using GIT with the command line, you can use the git status command to query which branch you are working on now, but it's hard to forget what branch you're under, so you have a mug with a wrong operation. It is no doubt convenient to display the branch in the Shell prompt, and no longer need to use the git status command very frequently ...

Not much nonsense, directly on the code, put in ~/.bash_profile or ~/.profile can

# # Parses outThe branch name from. git/Head:find_git_branch () {Local dir=. Head until ["$dir"-ef/]; Do    if[-F"$dir/.git/head" ]; Then head=$ (<"$dir/.git/head")      if[[$head =ref: \ Refs/heads/* ]]; Then git_branch= "→${head#*/*/}"elif [[$head! ="' ]]; Then Git_branch="→ (detached)"      ElseGit_branch="→ (unknow)"fireturnfi dir=".. /$dir"Done Git_branch="'}prompt_command="find_git_branch, $PROMPT _command"

# Heree

black=$' \[\e[1;30m\] '

red=$' \[\e[1;31m\] '

green=$' \[\e[1;32m\] '

yellow=$' \[\e[1;33m\] '

blue=$' \[\e[1;34m\] '

magenta=$' \[\e[1;35m\] '

cyan=$' \[\e[1;36m\] '

white=$' \[\e[1;37m\] '

normal=$' \[\e[m\] '

ps1="$white [$magenta \[email protected] $green \h$white: $cyan \w$yellow\ $git _branch$white]\$ $normal"

Show Git branch name in Shell prompt

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.