linux bash 脚本获取git当前的分支名


linux bash 脚本获取git当前的分支名

1、方法一
#!/bin/bash
function git.branch {
  br=`git branch | grep "*"`
  echo ${br/* /}
}
git.branch
2、方法二

git symbolic-ref --short -q HEAD

3、测试脚本
#!/bin/bash

function obtain_git_branch {
  br=`git branch | grep "*"`
  echo ${br/* /}
}
result=`obtain_git_branch`
echo Current git branch is $result
if [ "$result" == "android_lollipop" ] 
 then  
   echo the branch is android_lollipop
 else
   echo the branch is not android_lollipop
fi


echo -e "\n \n"
get_branch=`git symbolic-ref --short -q HEAD`
echo  git branch is $get_branch

if [ "$get_branch" == "android_lollipop" ] 
 then  
   echo the branch is android_lollipop
 else
   echo the branch is not android_lollipop
fi


4、测试效果图
linux bash 脚本获取git当前的分支名_第1张图片

5、从测试效果看bash脚本里面可以识别出当前的git分支名,我们就可以根据不同的git分支名做不同的工作。

你可能感兴趣的:(linux,shell脚本)