【问题标题】:create a GitLab git repository using command line使用命令行创建 GitLab git 存储库
【发布时间】:2015-08-05 16:07:48
【问题描述】:

我有一个脚本可以从 GitHub 的命令行创建一个 git 存储库, 所以我的问题是当我尝试使用我的脚本在 GitLab 中创建一个新的仓库时,我的脚本不起作用!

repo_name=$1

dir_name=`basename $(pwd)`

if [ "$repo_name" = "" ]; then echo "Repo name (hit enter to use '$dir_name')?"  read repo_name fi

if [ "$repo_name" = "" ]; then repo_name=$dir_name fi

username="xxxxxx" if [ "$username" = "" ];  then echo "Could not find username, run 'git config --global github.user <username>'" invalid_credentials=1 fi

token="xxxxxxxx" if [ "$token" = "" ];  then echo "Could not find token, run 'git config --global github.token <token>'"  invalid_credentials=1 fi

echo -n "Creating Github repository '$repo_name' ..."  curl -u "$username:$token" https://api.github.com/user/repos -d '{"name":"'$repo_name'"}' > /dev/null 2>&1 echo " done."

echo -n "Pushing local code to remote ..."  git remote add origin git@github.com:$username/$repo_name.git > /dev/null 2>&1 git push -u origin master > /dev/null 2>&1  echo " done."

那么这个相当于什么

curl -u "$username:$token" https://api.github.com/user/repos -d '{"name":"'$repo_name'"}'

在 GitLab 中?

感谢您的阅读!

【问题讨论】:

  • 您好!究竟什么不起作用,您遇到的具体错误是什么?

标签: git curl github


【解决方案1】:

您可以尝试使用curl -H "Content-Type:application/json" https://gitlab.com/api/v3/projects?private_token=&lt;your token&gt; -d "{ \"name\": \"&lt;new repo name&gt;\" }"(将 gitlab url 替换为您的服务器实例的 url)

【讨论】:

  • 感谢兄弟的解决方案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-04
  • 1970-01-01
  • 2016-01-11
  • 1970-01-01
相关资源
最近更新 更多