我创建了一个新的本地Git存储库:

~$ mkdir projectname
~$ cd projectname
~$ git init
~$ touch file1
~$ git add file1
~$ git commit -m 'first commit'

有没有任何git命令来创建一个新的远程回购,并从这里将我的提交推到GitHub ?我知道打开浏览器去创建一个新的存储库并不是什么大问题,但是如果有一种方法可以从CLI实现这一点,我会很高兴。

我读了大量的文章,但没有一篇提到如何使用git命令从CLI创建远程回购。Tim Lucas的一篇不错的文章“设置一个新的远程git存储库”是我找到的最接近的文章,但是GitHub不提供shell访问。


当前回答

最后,GitHub正式宣布了他们所有核心功能的新CLI。

点击这里查看:https://cli.github.com/

通过HomeBrew安装:brew install gh用于其他方式:https://github.com/cli/cli#installation

then

gh repo create

其他可用的特性。

$ gh --help

Work seamlessly with GitHub from the command line.

USAGE
  gh <command> <subcommand> [flags]

CORE COMMANDS
  gist:       Create gists
  issue:      Manage issues
  pr:         Manage pull requests
  release:    Manage GitHub releases
  repo:       Create, clone, fork, and view repositories

ADDITIONAL COMMANDS
  alias:      Create command shortcuts
  api:        Make an authenticated GitHub API request
  auth:       Login, logout, and refresh your authentication
  completion: Generate shell completion scripts
  config:     Manage configuration for gh
  help:       Help about any command

FLAGS
  --help      Show help for command
  --version   Show gh version

EXAMPLES
  $ gh issue create
  $ gh repo clone cli/cli
  $ gh pr checkout 321

ENVIRONMENT VARIABLES
  See 'gh help environment' for the list of supported environment variables.

LEARN MORE
  Use 'gh <command> <subcommand> --help' for more information about a command.
  Read the manual at https://cli.github.com/manual

FEEDBACK
  Open an issue using 'gh issue create -R cli/cli'

现在你可以在终端上创建repo了。

其他回答

找到了我喜欢的解决方案:https://medium.com/@jakehasler/ howto -create-a-remote-git-repo- fromm-the-command -line-2d6857f49564

你首先需要创建一个Github个人访问令牌

打开你的~/。Bash_profile或~/。Bashrc在您最喜欢的文本编辑器。在文件顶部附近添加以下一行,这里是导出的其他变量所在的位置:

出口GITHUB_API_TOKEN = < your-token-here >

在下面的某个地方,通过你的其他bash函数,你可以粘贴类似于下面的东西:

function new-git() {
    curl -X POST https://api.github.com/user/repos -u <your-username>:$GITHUB_API_TOKEN -d '{"name":"'$1'"}'
}

现在,当你创建一个新项目时,你可以运行命令$ new-git awesome-repo在你的Github用户帐户上创建一个新的公共远程存储库。

更新20200714

Github有了一个新的官方CLI。

...gh是一个新项目,帮助我们探索官方GitHub CLI工具在完全不同的设计下可以是什么样子。虽然这两个工具都将GitHub带到终端,但hub充当git的代理,而gh是一个独立的工具。

与hub的核心区别在于,它不会覆盖现有的git命令。所以,你不能像使用hub一样,将git别名为gh。

我们没有将它添加到hub,因为我们决定将GitHub CLI设计成与git包装器不同的方式,即作为它自己的命令。事实证明,维护一个作为git代理的可执行文件是很难维护的,而且我们也不想被总是保持git兼容性所限制。我们不想在一个从一开始就很脆弱的范例上构建GitHub CLI。

——mislav(轮毂维护人员)

原来的答案

你需要的是枢纽。Hub是git的命令行包装器。它已经使用别名与本地git集成。它试图提供github操作到git,包括创建新的存储库。

→  create a repo for a new project
$ git init
$ git add . && git commit -m "It begins."
$ git create -d "My new thing"
→  (creates a new project on GitHub with the name of current directory)
$ git push origin master

ruby开发者:

gem install githubrepo
githubrepo create *reponame*

根据提示输入username和pw

git remote add origin *ctrl v*
git push origin master

来源:Elikem Adadevoh

我用GitHub和BitBucket的REST api写了一个漂亮的脚本,叫做Gitter:

https://github.com/dderiso/gitter

BitBucket都:

gitter -c -r b -l javascript -n node_app

GitHub:

gitter -c -r g -l javascript -n node_app

-c =创建新的repo -r = repo provider (g = GitHub, b = BitBucket) -n =命名回购 -l = (optional)设置repo中应用程序的语言

在命令行上创建一个新的存储库

echo "# <RepositoryName>" >> README.md

git init

git add README.md

git commit -m "first commit"

git remote add origin https://github.com/**<gituserID>/<RepositoryName>**.git

git push -u origin master

从命令行推送现有存储库

git remote add origin https://github.com/**<gituserID>/<RepositoryName>**.git

git push -u origin master