Git分支使用源代码

时间:2015-08-03 07:45:14

标签: git bash github

我使用shell脚本使用我的项目自动执行git brnach。代码说明

  • 我要去源目录
  • 我正在进行远程更新
  • 如果用户输入错误的分支名称
  • ,我要求用户输入分支
  • 如果分支doest不存在捕获错误并显示用户,否则git checkout并从分支中提取代码

    *

     #!/bin/bash    
            cd application/src/
            git remote update
            echo "please check all the available branch in git"
            git branch
    
            echo "Please enter the branch name: "
            read branch_name
            echo "You entered: $branch_name"
    
            branch=$(git branch)
            files=(branch*)
    
            select SEL in "${files[@]}"
    
    
         do
                if  [[ "$SEL" ] !== '(no branch)']
                then
                    echo "Choose one of the available branch."
                    break
    
    
    
             else
                    git checkout $branch_name
                    git pull origin $branch_name
    
    done 
    
    
        git checkout $branch_name    
        git branch    
        git pull origin $branch_name*
    

我收到了这个错误。

Please enter the branch name:
1.5
You entered: 1.5
ram: line 21: conditional binary operator expected
ram: line 21: syntax error near `]'
ram: line 21: `    if  [[ "$SEL" ] !== '(no branch)']'

有人可以帮忙..

1 个答案:

答案 0 :(得分:0)

为什么要将[ ]放在$SEL附近。将其改写为:

if  [ "$SEL" !== '(no branch)']'