首页 > 解决方案 > Shell:Git 存储库创建脚本不向上游推送远程

问题描述

下面我有一个没有推送它的 shell 脚本,它在上游创建了远程分支。

我在本地测试了脚本,发现确实正在创建分支,但是一旦脚本到达该行,它似乎就中断了git push -u origin master

如果有人能指出我做错了什么,将不胜感激。

#!/bin/sh
set +x
localPath=$HOME/repos
token=""
instance=https://gitlab.####.com/api/v4
namespace_id=2 #This is the Flag group on our Gitlab instance. 

# On first use, prompt user to input the Gitlab Private API token. Then, store it for future uses as token.txt. 
if [ -f token.txt ]
    then
    read token < token.txt
else 
    read -p "Please input your Gitlab Private API Token from your user profile (https://gitlab.####.com/profile/account): " token
    echo $token > token.txt
    $token < token.txt
fi

for eachRepoName
    do
        #Local Work
        mkdir -p $localPath
        mkdir -p $localPath/$eachRepoName
        cp Master-Ignore-List.txt $localPath/$eachRepoName/.gitignore
        cd $localPath/$eachRepoName/
        echo "pre-git"
        git init
        touch README.md
        git add README.md .gitignore
        echo "about to commit"
        git commit -m "First Commit"
        #End Local Work

        curl -w "%{http_code}\n" --header "PRIVATE-TOKEN: $token" -X POST "$instance/projects?name=$eachRepoName&namespace_id=$namespace_id"

        git remote add origin https://gitlab.####.com/flag/$eachRepoName.git
        git push -u origin master
        git checkout -b development
        git push -u origin development 
        git remote set-head origin master 
        git branch -a
    done

标签: gitshell

解决方案


推荐阅读