从命令行创建Github存储库 [英] Creating Github Repository from command line

查看:78
本文介绍了从命令行创建Github存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.com上创建了远程仓库,并使用添加远程仓库URL.

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

git remote add origin https://mygithubrepoUrl.com

它奏效了.

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

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?

推荐答案

您需要先创建存储库,然后再进行推送,但是 hub 为您自动执行此操作:

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

git init newRepo
cd newRepo
hub create

使用-p切换到hub create来创建私有存储库.要推送本地master分支,请发出:

Use the -p switch to hub create to create a private repository. To push the local master branch, issue:

git push -u origin HEAD

该工具还可以创建拉取请求,打开项目页面,检查CI状态,仅指定username/repo克隆现有存储库以及其他一些内容.

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.

项目页面建议将git别名为hub(因为后者会将未知命令转发给git),但是我不推荐这样做,即使只是为了区分hubhub >糖果.

The project page suggests aliasing git to 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 hub candy.

这篇关于从命令行创建Github存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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