git 从命令行创建 Github 存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35124997/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:45:46  来源:igfitidea点击:

Creating Github Repository from command line

gitgithubrepository

提问by user2498079

I have been trying to push my local repo changes to github from command line. I have been away from git for a while now so I don't remember a few things. For the past hour I have been trying to push the repo without creating a remote repo on Github.com. As far as I remember, git push origin master/ git push is enough to push the local changes and if necessary create a repo on the remote server. However git push wouldn't let me push and automatically create the repo.

我一直在尝试从命令行将我的本地存储库更改推送到 github。我已经离开 git 一段时间了,所以我不记得一些事情了。在过去的一个小时里,我一直在尝试推送 repo,而不在 Github.com 上创建远程 repo。据我所知, git push origin master/ git push 足以推送本地更改,并在必要时在远程服务器上创建一个仓库。但是 git push 不会让我推送并自动创建回购。

So to save time, I created remote repo on github.com and add the remote repo url using

为了节省时间,我在 github.com 上创建了远程仓库并使用添加远程仓库 url

git remote add origin https://mygithubrepoUrl.com

git remote add origin https://mygithubrepoUrl.com

and it worked.

它奏效了。

Is it necessary to create remote repo on Github and then add this url from command line to push changes? Can't Git automatically create repo and push changes?

是否有必要在 Github 上创建远程仓库,然后从命令行添加这个 url 以推送更改?Git 不能自动创建 repo 并推送更改吗?

回答by krlmlr

You need to create the repo before pushing, but there's hubthat automates this for you:

您需要在推送之前创建 repo,但是hub可以为您自动执行此操作:

git init newRepo
cd newRepo
hub create

Use the -pswitch to hub createto create a private repository. To push the local masterbranch, issue:

使用-p开关来hub create创建私有存储库。要推送本地master分支,请发出:

git push -u origin HEAD

The tool can also create pull requests, open the project page, check the CI status, clone existing repos by specifying only username/repo, and a few more things.

该工具还可以创建拉取请求、打开项目页面、检查 CI 状态、通过仅指定克隆现有存储库username/repo等等。

The project page suggests aliasing gitto hub(because the latter forwards unknown commands to git), but I don't recommend this, even if just to distinguish "bare" Git commands from the hubcandy.

该项目页面建议别名github(因为后者向前未知命令git),但我不建议这样做,哪怕只是区分“裸”从Git命令hub糖果。

回答by mickiewicz

Github API should make work.

Github API 应该可以工作。

First create repo using curland API https://developer.github.com/v3/repos/#create

首先使用curl和 API https://developer.github.com/v3/repos/#create创建 repo

something like: curl -u 'username' https://api.github.com/user/repos -d '{"name":"repository name"}'

就像是: curl -u 'username' https://api.github.com/user/repos -d '{"name":"repository name"}'

and then you can add remote and push as you have described before:

然后你可以像之前描述的那样添加远程和推送:

git remote add origin [email protected]:user/repository_name.git && git push origin master

git remote add origin [email protected]:user/repository_name.git && git push origin master

回答by VonC

cli.github.comis now the successor of hub.

cli.github.com现在是 hub 的继承者。

It allows for repository creation from command line, since cli 0.6, and PR 547

它允许从命令行创建存储库,因为cli 0.6PR 547

Create a new GitHub repository.

创建一个新的 GitHub 存储库。

Usage:

Create a new GitHub repository.

Use the "ORG/NAME" syntax to create a repository within your organization.

Usage:

gh repo create [<name>] [flags]

Flags:

-d, --description string   Description of repository
    --enable-issues        Enable issues in the new repository (default true)
    --enable-wiki          Enable wiki in the new repository (default true)
-h, --homepage string      Repository home page URL
    --public               Make the new repository public
-t, --team string          The name of the organization team to be granted access

Global Flags:

 --help                  Show help for command
 -R, --repo OWNER/REPO   Select another repository using the OWNER/REPO format

用法:

创建一个新的 GitHub 存储库。

使用 " ORG/NAME" 语法在您的组织内创建存储库。

用法:

gh repo create [<name>] [flags]

标志:

-d, --description string   Description of repository
    --enable-issues        Enable issues in the new repository (default true)
    --enable-wiki          Enable wiki in the new repository (default true)
-h, --homepage string      Repository home page URL
    --public               Make the new repository public
-t, --team string          The name of the organization team to be granted access

全局标志:

 --help                  Show help for command
 -R, --repo OWNER/REPO   Select another repository using the OWNER/REPO format