如何使用 CLI 从我现有的本地 git 存储库创建新的 gitlab 存储库? [英] How to create a new gitlab repo from my existing local git repo, using CLI?

查看:11
本文介绍了如何使用 CLI 从我现有的本地 git 存储库创建新的 gitlab 存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 OSX 上有许多本地 git 存储库.使用命令行,我想从现有的本地存储库中在 https://gitlab.companyname.com 上创建新的 gitlab 存储库.

有可能吗?

解决方案

2018解决方案:直接使用--set-upstream

假设您将负责编写脚本,为您的每个本地存储库执行以下操作,似乎从 Gitlab 10.5 开始,您可以简单地使用

# 到你自己的域git push --set-upstream 地址/your-project.git# 使用 SSH 访问 gitlab.comgit push --set-upstream git@gitlab.example.com:username/new-repo.git master# 使用 HTTP 到 gitlab.comgit push --set-upstream https://gitlab.example.com/username/new-repo.git master

这将在 Gitlab 上创建一个新项目您无需在服务器上手动创建它


来自文档

推送创建一个新项目

<块引用>

当你在本地创建一个新的仓库时,而不是在 GitLab 中手动创建一个新项目然后 在本地克隆存储库,您可以直接将其推送到 GitLab 以创建新项目,而无需离开终端.如果您有权访问关联的命名空间,GitLab 会自动在该 GitLab 命名空间下创建一个新项目,默认情况下其可见性设置为 Private(您可以稍后在 项目设置).

这可以通过使用 SSH 或 HTTPS 来完成:

## Git 使用 SSH 推送git push --set-upstream git@gitlab.example.com:namespace/nonexistent-project.git master## Git 使用 HTTPS 推送git push --set-upstream https://gitlab.example.com/namespace/nonexistent-project.git master

<块引用>

您可以将标志 --tags 传递给 git push 命令以导出现有的存储库标签.

推送成功完成后,会显示一条远程消息,指示设置远程的命令和新项目的 URL:

远程:远程:创建了私有项目命名空间/不存在的项目.偏僻的:远程:要配置远程,运行:远程:git 远程添加源 https://gitlab.example.com/namespace/nonexistent-project.git偏僻的:远程:要查看项目,请访问:远程:https://gitlab.example.com/namespace/nonexistent-project偏僻的:

I have many local git repos on my OSX. Using the command line I want to make new gitlab repositories on https://gitlab.companyname.com from existing local repositories.

Is it possible to do that?

解决方案

2018 Solution: just use --set-upstream

Assuming you'll take care of writing the script that would do the following for each of your local repo, it seems that as of Gitlab 10.5 you can simply use

# To your own domain
git push --set-upstream address/your-project.git

# To gitlab.com with SSH
git push --set-upstream git@gitlab.example.com:username/new-repo.git master

# To gitlab.com with HTTP
git push --set-upstream https://gitlab.example.com/username/new-repo.git master

This will create a new project on Gitlab without you creating it manually on the server


From the Documentation

Push to create a new project

When you create a new repository locally, instead of manually creating a new project in GitLab and then cloning the repository locally, you can directly push it to GitLab to create the new project, all without leaving your terminal. If you have access rights to the associated namespace, GitLab automatically creates a new project under that GitLab namespace with its visibility set to Private by default (you can later change it in the project's settings).

This can be done by using either SSH or HTTPS:

## Git push using SSH
git push --set-upstream git@gitlab.example.com:namespace/nonexistent-project.git master

## Git push using HTTPS
git push --set-upstream https://gitlab.example.com/namespace/nonexistent-project.git master

You can pass the flag --tags to the git push command to export existing repository tags.

Once the push finishes successfully, a remote message indicates the command to set the remote and the URL to the new project:

remote:
remote: The private project namespace/nonexistent-project was created.
remote:
remote: To configure the remote, run:
remote:   git remote add origin https://gitlab.example.com/namespace/nonexistent-project.git
remote:
remote: To view the project, visit:
remote:   https://gitlab.example.com/namespace/nonexistent-project
remote:

这篇关于如何使用 CLI 从我现有的本地 git 存储库创建新的 gitlab 存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆