> For the complete documentation index, see [llms.txt](https://jun-wang.gitbook.io/learnjava/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jun-wang.gitbook.io/learnjava/xiaolti-sheng/mac-xia-xian-shi-git-fen-zhi.md).

# Mac下显示git分支

通常情况下我们在git目录中，使用`git branch`来查看分支，这样很麻烦繁琐，不如直接显示来的直接。下面我们来介绍一下如何在mac的终端中显示git分支。这里提供一个简单的办法，使用zsh并配置，顺便安利一下mac的终极shell——zsh，关于zsh的一些介绍可以参考：<http://macshuo.com/?p=676。本文主要讲如何显示git分支。>

```
# 先来查看一下mac支持的shell：
cat /etc/shells 
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
# 查看当前使用的shell
echo $SHELL
/bin/bash
# 切换成zsh，重启终端后生效
chsh -s /bin/zsh
# 安装on my zsh，假设你已经安装了git
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
# 重启一下终端，然后进入到一个git目录中去，就可以看到分支啦。
```

**注意：**&#x7531;于切换了shell，所以之前在\~/.bashrc里面的配置都不生效了，需要配置在\~/.zshrc里面。
