git 使用 CLI 在 gitlab 中创建一个 repo
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19585211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
creating a repo in gitlab using CLI
提问by Brij Raj Singh - MSFT
We have a gitlab
setup at our office, and we have somewhat around 100-150 project each week to create over there, while Admin wants to keep the control of creating repos and assigning teams to it, it seems quite a bit of task for anyone to create that many repos every week.
我们gitlab
在办公室有一个设置,我们每周有大约 100-150 个项目要在那里创建,而管理员希望保持对创建 repos 和分配团队的控制权,这对任何人来说似乎都是一项艰巨的任务每周创建那么多的回购。
Is there a way to create repo on Gitlab using CLI
- I won't mind if i have to use ssh
for it.
有没有办法create repo on Gitlab using CLI
- 我不介意我是否必须使用ssh
它。
采纳答案by thameera
You can use gitlab-cliand automate the process using a shell script. I've used this in gitlab 5.x, but according to the site it might not work with gitlab 6.
您可以使用gitlab-cli并使用 shell 脚本自动执行该过程。我在 gitlab 5.x 中使用过它,但根据该站点,它可能不适用于 gitlab 6。
回答by Michael Lihs
gitlab-cliis no longer maintained, the author references the Gitlabmodule to be used instead - it also includes a CLI tool.
gitlab-cli不再维护,作者引用了要使用的Gitlab模块 - 它还包含一个 CLI 工具。
For your specific request - namely creating a project on the command line, use the following command:
对于您的特定请求 - 即在命令行上创建一个项目,请使用以下命令:
gitlab create_project "YOUR_PROJECT_NAME" "{namespace_id: 'YOUR_NUMERIC_GROUP_ID'}"
gitlab create_project "YOUR_PROJECT_NAME" "{namespace_id: 'YOUR_NUMERIC_GROUP_ID'}"
Be sure to use the option namespace_id
and not group_id
! If you are not sure what your GROUP_ID
is, you can use
一定要使用选项namespace_id
而不是group_id
!如果您不确定自己GROUP_ID
是什么,可以使用
gitlab groups | grep YOUR_GROUP_NAME
gitlab groups | grep YOUR_GROUP_NAME
to find out.
找出答案。
The parameters for each command can be inferred from the API documentation. Any non-scalar valued parameter has to be encoded in an inline YAML syntax (as above).
每个命令的参数可以从API 文档中推断出来。任何非标量值参数都必须以内联 YAML 语法(如上)编码。
回答by ChillarAnand
Since you just wanted to create a repo, there is no need of third party apps. You can directly send a post request to gitlab API which will create repo.
由于您只想创建一个 repo,因此不需要第三方应用程序。您可以直接向 gitlab API 发送 post 请求,这将创建 repo。
Go to account tabin your profile, you will find a private token. Copy that.
转到您个人资料中的帐户选项卡,您将找到一个私人令牌。收到。
Now open terminal and run this command with private token (say foo
) and your repo name (say bar
).
现在打开终端并使用私有令牌(例如foo
)和您的存储库名称(例如bar
)运行此命令。
curl -H "Content-Type:application/json" https://gitlab.com/api/v4/projects?private_token=foo -d "{ \"name\": \"bar\" }"
For convenience, you can create a shell script, if you don't want to run this command every time.
为方便起见,如果您不想每次都运行此命令,您可以创建一个 shell 脚本。
#!/bin/sh
curl -H "Content-Type:application/json" https://gitlab.com/api/v4/projects?private_token=foo -d "{ \"name\": \"\" }"
Save this to a file gcr.sh
and make it executable using chmod +x gcr.sh
.
将其保存到文件中gcr.sh
并使用chmod +x gcr.sh
.
Now to create a repo name bar
, run
现在要创建一个回购名称bar
,运行
$ ./gcr.sh bar
回答by Саша Черных
1. Summary
一、总结
Easy to use:
便于使用:
2. Disclaimer
2. 免责声明
This answer is relevant for August 2019. In the future, its data may be outdated.
此答案与 2019 年 8 月相关。未来,其数据可能已过时。
3. lab (recommended)
3.实验室(推荐)
3.1. About
3.1. 关于
lab — CLI tool, making it simple some operations with GitLab repositories. lab is Gitlab equivalent of hubextension for GitHub.
lab — CLI 工具,使 GitLab 存储库的一些操作变得简单。lab 是 Gitlab 相当于GitHub的集线器扩展。
3.2. Usage
3.2. 用法
After first run lab will offer to enter token. Create a personal access tokenwith desired scope api
→ paste it to terminal → Enter.
首次运行后,实验室将提供输入令牌。创建具有所需范围的个人访问令牌api
→ 将其粘贴到终端 → Enter。
Then run lab project create
:
然后运行lab project create
:
lab project create -n KiraLab --public -d "Kira lab demo project"
3.3. Result
3.3. 结果
3.4. Why recommended
3.4. 为什么推荐
Options are available:
可用选项:
--public
— making repository public, not private-d
,--description
— creating description
--public
- 使存储库公开,而不是私有-d
,--description
— 创建描述
4. gitlab-cli
4. gitlab-cli
4.1. About
4.1. 关于
Cross-platform Go-written command-line utility for GitLab repositories operations.
用于 GitLab 存储库操作的跨平台 Go 编写的命令行实用程序。
4.2. Usage
4.2. 用法
Create your GitLab personal access token→ gitlab-cli login YOUR_TOKEN
→ run gitlab-cli project create
command:
创建您的 GitLab 个人访问令牌→gitlab-cli login YOUR_TOKEN
→ 运行gitlab-cli project create
命令:
gitlab-cli project create KiraGitLabCLI
4.3. Result
4.3. 结果
4.4. Note
4.4. 笔记
Please do not confuse this Go project and Ruby gitlab-clitool from @thameera answer.
请不要混淆这个 Go 项目和来自@thameera answer 的Ruby gitlab-cli工具。
5. External links
5. 外部链接
回答by typelogic
Here is what I have in my ~/.bashrc
这是我的 ~/.bashrc 中的内容
gitlify() {
[ $# -eq 0 ] && return 1
repo_name=
username=smeagol
token=01234567890
curl -H "Content-Type:application/json" https://gitlab.com/api/v4/projects?private_token=$token -d "{\"name\": \"$repo_name\"}"
if [ $? -eq 0 ];then
git init
git add .
git commit -m "first blood"
git remote add origin [email protected]:$username/$repo_name.git
git push -u origin master
else
echo "error create gitlab repo $repo_name"
fi
}
You have to first have a token for your username. Once this bash function is in placed, you can use it by:
您必须首先拥有一个用于您的用户名的令牌。放置此 bash 函数后,您可以通过以下方式使用它:
mkdir /tmp/firstblood
echo '#hello world' > /tmp/firstblood/README.md
cd /tmp/firstblood
gitlify fallenangel
This snippet is only for gitlab.com. I have another one that I named gitifyfor github.com.
此代码段仅适用于 gitlab.com。我还有另一个名为gitify的 github.com。