我创建了一个新的本地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访问。


当前回答

这是我的初始git命令(可能,这个操作发生在C:/Documents and Settings/your_username/):

mkdir ~/Hello-World
# Creates a directory for your project called "Hello-World" in your user directory
cd ~/Hello-World
# Changes the current working directory to your newly created directory
touch blabla.html
# create a file, named blabla.html
git init
# Sets up the necessary Git files
git add blabla.html
# Stages your blabla.html file, adding it to the list of files to be committed
git commit -m 'first committttt'
# Commits your files, adding the message 
git remote add origin https://github.com/username/Hello-World.git
# Creates a remote named "origin" pointing at your GitHub repository
git push -u origin master
# Sends your commits in the "master" branch to GitHub

其他回答

有关创建令牌的说明,请转到这里。这是您将键入的命令(从回答的日期开始)。(替换所有CAPS关键字):

curl -u 'YOUR_USERNAME' -d '{"scopes":["repo"],"note":"YOUR_NOTE"}' https://api.github.com/authorizations

输入密码后,您将看到下面包含您的令牌。

{
  "app": {
    "name": "YOUR_NOTE (API)",
    "url": "http://developer.github.com/v3/oauth/#oauth-authorizations-api"
  },
  "note_url": null,
  "note": "YOUR_NOTE",
  "scopes": [
    "repo"
  ],
  "created_at": "2012-10-04T14:17:20Z",
  "token": "xxxxx",
  "updated_at": "2012-10-04T14:17:20Z",
  "id": xxxxx,
  "url": "https://api.github.com/authorizations/697577"
}

您可以随时到这里撤销您的令牌

我用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中应用程序的语言

对于所有的Python 2.7。*用户。目前版本3的Github API有一个名为GitPython的Python包装器。只需使用easy_install PyGithub或pip install PyGithub安装即可。

from github import Github
g = Github(your-email-addr, your-passwd)
repo = g.get_user().user.create_repo("your-new-repos-name")

# Make use of Repository object (repo)

Repository对象文档在这里。

这是我的初始git命令(可能,这个操作发生在C:/Documents and Settings/your_username/):

mkdir ~/Hello-World
# Creates a directory for your project called "Hello-World" in your user directory
cd ~/Hello-World
# Changes the current working directory to your newly created directory
touch blabla.html
# create a file, named blabla.html
git init
# Sets up the necessary Git files
git add blabla.html
# Stages your blabla.html file, adding it to the list of files to be committed
git commit -m 'first committttt'
# Commits your files, adding the message 
git remote add origin https://github.com/username/Hello-World.git
# Creates a remote named "origin" pointing at your GitHub repository
git push -u origin master
# Sends your commits in the "master" branch to GitHub

ruby开发者:

gem install githubrepo
githubrepo create *reponame*

根据提示输入username和pw

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

来源:Elikem Adadevoh