我创建了一个新的本地Git仓库:
~$ mkdir projectname
~$ cd projectname
~$ git init
~$ touch file1
~$ git add file1
~$ git commit -m 'first commit'
是否有任何的git命令来创建一个新的远程回购和推动我在这里承诺GitHub上? 我知道这没什么大不了的,只是启动一个浏览器,头部到创建新的存储库 ,但如果从CLI的方式来实现这一点,我会很高兴。
我读的文章,但没有一个大量,我发现提及如何建立从CLI使用Git命令远程回购。 蒂姆·卢卡斯的好文章, 建立一个新的远程git仓库是我发现的最接近, 但GitHub上不提供shell访问 。
Answer 1:
您可以通过创建使用GitHub的API命令行GitHub库。 检查出库API 。 如果向下滚动有关的三分之一处,你会看到一个标题为部分“创建” ,介绍如何通过API(右上面是介绍如何叉的API回购节创建一个回购协议,也)。 显然,你不能使用git
做到这一点,但你可以通过使用类似工具的命令行做curl
。
该API之外,有没有办法通过命令行来创建在GitHub回购。 正如你提到的,GitHub上不允许shell访问等,从GitHub的API,以便留出,以创建一个回购的唯一途径是通过GitHub的Web界面。
Answer 2:
对GitHub的API V3 CLI命令(替换全部大写关键字):
curl -u 'USER' https://api.github.com/user/repos -d '{"name":"REPO"}'
# Remember replace USER with your username and REPO with your repository/application name!
git remote add origin git@github.com:USER/REPO.git
git push origin master
Answer 3:
这可以用三个命令来实现:
curl -u 'nyeates' https://api.github.com/user/repos -d '{"name":"projectname","description":"This project is a test"}'
git remote add origin git@github.com:nyeates/projectname.git
git push origin master
(更新为V3 Github的API)
这些命令的解释...
创建GitHub库
curl -u 'nyeates' https://api.github.com/user/repos -d '{"name":"projectname","description":"This project is a test"}'
- 卷曲是unix命令(上文关于MAC太作品),其检索并与网址相互作用。 它通常已安装。
- “-u”是指定用于服务器认证的用户名和密码的卷曲参数。
- 如果你给的用户名(如上面的例子中)袅袅会提示输入密码。
- 如果你不希望在键入密码,看到githubs API文档认证
- “-D”是让你与请求发送POST数据的卷曲参数
- 您在githubs发送POST数据定义的API格式
- “name”是唯一需要的POST数据; 我喜欢还包括“说明”
- 我发现,这是很好的报价单引号“”所有的POST数据
定义在哪儿推
git remote add origin git@github.com:nyeates/projectname.git
- 添加定义位置和在github连接(远程)回购所有脑干
- “原产地”是源来自何处使用Git的默认名称
- 技术上没有来从GitHub,但现在的GitHub库将记录的来源
- “git@github.com:nyeates”是假设你已经安装可信SSH密钥对与github上一个ssh连接。
按本地回购到github上
git push origin master
Answer 4:
如果安装德芬克特的优秀中心的工具,那么这将成为一样简单
git create
在笔者的话来说,“ 中心是git的命令行包装,让你在GitHub上更好。”
Answer 5:
简单的步骤(使用git
+ hub
=> 的GitHub):
安装集线器 ( GitHub上 )。
转到您的回购或建立空单: mkdir foo && cd foo && git init
。
兼营: hub create
,它会问你关于GitHub的凭据首次。
用法: hub create [-p] [-d DESCRIPTION] [-h HOMEPAGE] [NAME]
例如: hub create -d Description -h example.com org_name/foo_repo
集线器将提示GitHub的用户名和密码,它需要访问API和交换它用于在第一时间OAuth
令牌,它在保存~/.config/hub
。
要明确命名新的存储库,通过在NAME
,任选在ORGANIZATION/NAME
形式你是成员的组织下创建。
随着-p
,创建一个私有的存储库,并与-d
和-h
设置仓库的描述和网页URL
分别。
为了避免被提示时,使用GITHUB_USER
和GITHUB_PASSWORD
环境变量。
然后提交并推送照常或检查hub commit
/ hub push
。
如需更多帮助,请运行: hub help
。
另请参阅: 导入使用命令行一个Git仓库在GitHub上。
Answer 6:
有一个官方github上的宝石其中,我认为,这样做了。 我会尝试添加更多的信息,因为我学习,但我现在才发现这个宝石,所以我不知道多少呢。
更新:设置我的API密钥之后,我能够通过在GitHub上创建一个新的回购create
的命令,但是我不能够使用的create-from-local
命令,这是应该拿现在的本地仓库,并作出对应的远程出在github。
$ gh create-from-local
=> error creating repository
如果任何人有这方面的一些见解,我很想知道我做错了。 有一个已经提交的问题 。
更新:我没有最终得到这个工作。 我不完全知道如何重新产生问题,但我只是从零开始(删除git的文件夹)
git init
git add .emacs
git commit -a -m "adding emacs"
现在,这条线将创建远程回购,甚至推到它,但不幸的是,我不认为我可以指定我想回购的名称。 我希望它被称为出在github上“点文件”,但GH宝石只是用来在当前文件夹,这是“杰森”,因为我是在我的主文件夹的名称。 (我加票要求所需的行为)
gh create-from-local
这个命令,在另一方面,不接受任何参数指定远程回购的名字,但它打算从头开始一个新项目,以后你也就是调用这个命令,你得到的追踪本地回购新的远程回购在新创建相对于您的当前位置的子文件夹,都与名称指定为参数。
gh create dotfiles
Answer 7:
要快速通过使用bash shell中创建远程仓库
这是很麻烦,每次存储库是要创建键入完整的代码
curl -u 'USER' https://api.github.com/user/repos -d '{"name":"REPO"}' git remote add origin git@github.com:USER/REPO.git git push origin master
一种更简单的方法是:
- 创建一个目录如/家庭/ USER_NAME /桌面shell脚本/ my_scripts命名
githubscript.sh
- 修改和下面的代码保存到
githubscript.sh
文件
#!bin/bash
curl -u 'YOUR_GITHUB_USER_NAME' https://api.github.com/user/repos -d "{\"name\":\"$1\"}";
git init;
git remote add origin git@github.com:YOUR_GITHUB_USER_NAME/$1.git;
NB 这里$1
是repository name
是作为传递argument
调用时script
更改YOUR_GITHUB_USER_NAME
保存脚本之前。
设置必要的权限script
文件chmod 755 githubscript.sh
包括环境配置文件中的scripts目录。 nano ~/.profile; export PATH="$PATH:$HOME/Desktop/my_scripts"
同时设定一个别名运行的githubscript.sh文件。 nano ~/.bashrc; alias githubrepo="bash githubscript.sh"
现在重新加载.bashrc
和.profile
在终端的文件。 source ~/.bashrc ~/.profile;
现在创建一个新的存储库即demo
: githubrepo demo;
Answer 8:
对于双因素身份验证的用户,可以使用bennedich的解决方案,但你只需要添加X-Github上-OTP头的第一个命令。 与您从双因素认证提供商处获得的代码替换代码。 与存储库的用户名和名称替换USER和REPO,就像在他的解决方案。
curl -u 'USER' -H "X-GitHub-OTP: CODE" -d '{"name":"REPO"}' https://api.github.com/user/repos
git remote add origin git@github.com:USER/REPO.git
git push origin master
Answer 9:
不,你必须打开浏览器ATLEAST一次以创建您的username
在GitHub上,一旦创建,您可以利用GitHub的API来创建命令行库,按照下面的命令:
curl -u 'github-username' https://api.github.com/user/repos -d '{"name":"repo-name"}'
例如:
curl -u 'arpitaggarwal' https://api.github.com/user/repos -d '{"name":"command-line-repo"}'
Answer 10:
我写了一个漂亮的脚本此使用REST API进行的GitHub和到位桶所谓的Gitter:
https://github.com/dderiso/gitter
到位桶:
gitter -c -r b -l javascript -n node_app
GitHub的:
gitter -c -r g -l javascript -n node_app
-
-c
=创建新的回购 -
-r
=回购提供商(G = GitHub的,B =到位桶) -
-n
=命名回购 -
-l
=(可选)中设置的应用程序的语言中回购
Answer 11:
我创建了一个Git的别名,要做到这一点,基于Bennedich的答案 。 以下添加到您的~/.gitconfig
:
[github]
user = "your_github_username"
[alias]
; Creates a new Github repo under the account specified by github.user.
; The remote repo name is taken from the local repo's directory name.
; Note: Referring to the current directory works because Git executes "!" shell commands in the repo root directory.
hub-new-repo = "!python3 -c 'from subprocess import *; import os; from os.path import *; user = check_output([\"git\", \"config\", \"--get\", \"github.user\"]).decode(\"utf8\").strip(); repo = splitext(basename(os.getcwd()))[0]; check_call([\"curl\", \"-u\", user, \"https://api.github.com/user/repos\", \"-d\", \"{{\\\"name\\\": \\\"{0}\\\"}}\".format(repo), \"--fail\"]); check_call([\"git\", \"remote\", \"add\", \"origin\", \"git@github.com:{0}/{1}.git\".format(user, repo)]); check_call([\"git\", \"push\", \"origin\", \"master\"])'"
要使用它,跑
$ git hub-new-repo
从本地仓库内的任意位置,并按提示输入您的密码Github上。
Answer 12:
对于Ruby开发者:
gem install githubrepo
githubrepo create *reponame*
按提示输入用户名和PW
git remote add origin *ctrl v*
git push origin master
来源: Elikem Adadevoh
Answer 13:
基于由@Mechanical蜗牛,对方的回答只是没有使用Python的,我认为是疯狂矫枉过正。 添加到您的~/.gitconfig
:
[github]
user = "your-name-here"
[alias]
hub-new-repo = "!REPO=$(basename $PWD) GHUSER=$(git config --get github.user); curl -u $GHUSER https://api.github.com/user/repos -d {\\\"name\\\":\\\"$REPO\\\"} --fail; git remote add origin git@github.com:$GHUSER/$REPO.git; git push origin master"
Answer 14:
有关创建令牌方向,走在这里这是您将类型(这个答案的日期的命令(替换所有大写关键字):
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"
}
您可以通过随时撤销您的令牌这里
Answer 15:
你需要的是枢纽 。 轮毂是git的命令行包装。 它已经取得了使用别名本地git的整合。 它试图提供的github行动统一到混帐包括创建新的存储库。
→ 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
Answer 16:
对于代表的原因,我不能将其添加为注释(它会更好地去bennedich的答案 ),但对于Windows命令行,这里是正确的语法:
卷曲-u YOUR_USERNAME https://api.github.com/user/repos -d “{\”名称\ “:\” YOUR_REPO_NAME \ “}”
这是相同的基本形式,但你必须用双引号(“),而不是单一的,而逃脱反斜杠在POST参数发送(-d标志后)双引号。我也删除在我的用户名的单引号,但如果你的用户名有空间(可能吗?),它可能需要双引号。
Answer 17:
对于所有的Python 2.7。*的用户。 周围有一个Python包装Github的API与目前版本3,称为GitPython 。 只需安装使用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
对象文档是在这里 。
Answer 18:
Disclamier:我是开源项目的作者
此功能是通过支持: https://github.com/chrissound/Human-Friendly-Commands本质上就是这个脚本:
#!/usr/bin/env bash
# Create a repo named by the current directory
# Accepts 1 STRING parameter for the repo description
# Depends on bin: jq
# Depends on env: GITHUB_USER, GITHUB_API_TOKEN
github_createRepo() {
projName="$(basename "$PWD")"
json=$(jq -n \
--arg name "$projName" \
--arg description "$1" \
'{"name":$name, "description":$description}')
curl -u "$GITHUB_USER":"$GITHUB_API_TOKEN" https://api.github.com/user/repos -d "$json"
git init
git remote add origin git@github.com:"$GITHUB_USER"/"$projName".git
git push origin master
};
Answer 19:
发现了这个解决方案,我很喜欢: https://medium.com/@jakehasler/how-to-create-a-remote-git-repo-from-the-command-line-2d6857f49564
首先,您需要创建一个Github的个人访问令牌
打开你的〜/ .bash_profile中或在〜/ .bashrc在你喜欢的文本编辑器。 添加以下线附近的文件,其中出口“的其余编变量的顶部:
export 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上的用户帐户创建一个新的公共远程仓库。
Answer 20:
这是我的初始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
Answer 21:
我最近发现了创建-GitHub的回购 。 自述:
安装:
$ npm i -g create-github-repo
用法:
$ export CREATE_GITHUB_REPO_TOKEN=<access_token>
$ create-github-repo --name "My coolest repo yet!"
要么:
$ create-github-repo <access_token> --name "My coolest repo yet!"
Answer 22:
创建在命令行上一个新的存储库
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
文章来源: Is it possible to create a remote repo on GitHub from the CLI without opening browser?