Skip to content

Instantly share code, notes, and snippets.

@neo-yuanyanjun
Forked from yisibl/git-branch.md
Created June 4, 2019 12:23
Show Gist options
  • Save neo-yuanyanjun/151ba335e0400bd6d6fc4951a52860a4 to your computer and use it in GitHub Desktop.
Save neo-yuanyanjun/151ba335e0400bd6d6fc4951a52860a4 to your computer and use it in GitHub Desktop.

Revisions

  1. @yisibl yisibl revised this gist Jan 6, 2014. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions git-branch.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    # 在Mac、Linux 终端显示Git当前所在分支
    # 在Mac、Linux 终端显示 Git 当前所在分支

    1. 首先,要保证你已经安装了Git,Git安装教程见:Git 安装
    1. 进入你的‘home’目录
    1. 进入你的`home`目录


    ```
    @@ -39,7 +38,7 @@
    1. 完成


    >mac下面启动的shell是login shell,所以加载的配置文件是.bash_profile,不会加载.bashrc。如果你是mac用户的话,需要再执行下面的命令,这样每次开机后才会自动生效:
    >Mac 下面启动的 shell 是 login shell,所以加载的配置文件是`.bash_profile`,不会加载`.bashrc`。如果你是 Mac 用户的话,需要再执行下面的命令,这样每次开机后才会自动生效:
    ```
    echo "[ -r ~/.bashrc ] && source ~/.bashrc" >> .bash_profile
  2. @yisibl yisibl revised this gist Jan 6, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-branch.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # 在终端显示Git当前所在分支
    # 在Mac、Linux 终端显示Git当前所在分支

    1. 首先,要保证你已经安装了Git,Git安装教程见:Git 安装
    1. 进入你的‘home’目录
  3. @yisibl yisibl revised this gist Jan 6, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-branch.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # 在终端显示当前Git所在分支
    # 在终端显示Git当前所在分支

    1. 首先,要保证你已经安装了Git,Git安装教程见:Git 安装
    1. 进入你的‘home’目录
  4. @yisibl yisibl revised this gist Jan 6, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-branch.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@
    vi .bashrc
    ```

    将下面的代码加入到文件的最后处
    1. 将下面的代码加入到文件的最后处

    ```
    function git_branch {
  5. @yisibl yisibl revised this gist Jan 6, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions git-branch.md
    Original file line number Diff line number Diff line change
    @@ -17,17 +17,17 @@
    将下面的代码加入到文件的最后处

    ```
    function git_branch {
    function git_branch {
    branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"
    if [ "${branch}" != "" ];then
    if [ "${branch}" = "(no branch)" ];then
    branch="(`git rev-parse --short HEAD`...)"
    fi
    echo " ($branch)"
    fi
    }
    }
    export PS1='\u@\h \[\033[01;36m\]\W\[\033[01;32m\]$(git_branch)\[\033[00m\] \$ '
    export PS1='\u@\h \[\033[01;36m\]\W\[\033[01;32m\]$(git_branch)\[\033[00m\] \$ '
    ```
    1. 保存退出
    1. 执行加载命令
  6. @yisibl yisibl revised this gist Jan 6, 2014. 1 changed file with 15 additions and 15 deletions.
    30 changes: 15 additions & 15 deletions git-branch.md
    Original file line number Diff line number Diff line change
    @@ -4,19 +4,19 @@
    1. 进入你的‘home’目录


    ```
    cd ~
    ```
    ```
    cd ~
    ```

    1. 编辑`.bashrc`文件

    ```
    vi .bashrc
    ```
    ```
    vi .bashrc
    ```

    将下面的代码加入到文件的最后处

    ```
    ```
    function git_branch {
    branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"
    if [ "${branch}" != "" ];then
    @@ -28,19 +28,19 @@ function git_branch {
    }
    export PS1='\u@\h \[\033[01;36m\]\W\[\033[01;32m\]$(git_branch)\[\033[00m\] \$ '
    ```
    ```
    1. 保存退出
    1. 执行加载命令

    ```
    source ./.bashrc
    ```
    ```
    source ./.bashrc
    ```

    1. 完成


    >mac下面启动的shell是login shell,所以加载的配置文件是.bash_profile,不会加载.bashrc。如果你是mac用户的话,需要再执行下面的命令,这样每次开机后才会自动生效:
    >mac下面启动的shell是login shell,所以加载的配置文件是.bash_profile,不会加载.bashrc。如果你是mac用户的话,需要再执行下面的命令,这样每次开机后才会自动生效:
    ```
    echo "[ -r ~/.bashrc ] && source ~/.bashrc" >> .bash_profile
    ```
    ```
    echo "[ -r ~/.bashrc ] && source ~/.bashrc" >> .bash_profile
    ```
  7. @yisibl yisibl created this gist Jan 6, 2014.
    46 changes: 46 additions & 0 deletions git-branch.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    # 在终端显示当前Git所在分支

    1. 首先,要保证你已经安装了Git,Git安装教程见:Git 安装
    1. 进入你的‘home’目录


    ```
    cd ~
    ```

    1. 编辑`.bashrc`文件

    ```
    vi .bashrc
    ```

    将下面的代码加入到文件的最后处

    ```
    function git_branch {
    branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"
    if [ "${branch}" != "" ];then
    if [ "${branch}" = "(no branch)" ];then
    branch="(`git rev-parse --short HEAD`...)"
    fi
    echo " ($branch)"
    fi
    }
    export PS1='\u@\h \[\033[01;36m\]\W\[\033[01;32m\]$(git_branch)\[\033[00m\] \$ '
    ```
    1. 保存退出
    1. 执行加载命令

    ```
    source ./.bashrc
    ```

    1. 完成


    >mac下面启动的shell是login shell,所以加载的配置文件是.bash_profile,不会加载.bashrc。如果你是mac用户的话,需要再执行下面的命令,这样每次开机后才会自动生效:
    ```
    echo "[ -r ~/.bashrc ] && source ~/.bashrc" >> .bash_profile
    ```