2012-07-27 132 views
17

如何创建从使用Git的bash我的机器上一个新的资料库?如何创建在Github上使用Git的bash一个新的回购?

我也跟着下面的步骤:

mkdir ~/Hello-World 

cd ~/Hello-World 

git init 

touch README 

git add README 

git commit -m 'first commit' 

git remote add origin https://github.com/username/Hello-World.git 

git push origin master 

但我发现了“致命的错误:你在服务器上运行更新服务器的信息?”

+0

Duplicate http://stackoverflow.com/a/27456812/874188表明存在(现在?)一个API。 – tripleee 2014-12-13 08:26:52

回答

17

不能创建在github回购使用git bash。 Git和github是不同的东西。 Github是一个平台,让您在代码上进行托管和协作,而git是使用的版本控制工具。你可以阅读更多关于他们在维基百科上的文章:githubgit

但是,如果你的目的是要创建一个使用终端GitHub库,你可以使用GitHub的API和卷曲做到这一点。

1

只是试图在最后一行添加-u:

git push -u origin master 
+1

这不适用于创建新的回购。 -u是--set-upstream的缩写。这里解释得非常好:http://stackoverflow.com/questions/6089294/why-do-i-need-to-do-set-upstream-all-the-time – alexbhandari 2013-12-23 05:30:26

5

可能创造在github回购的最简单的方法是什么地方之前该行:

git remote add origin https://github.com/username/Hello-World.git 

https://github.com/new并在github上创建一个仓库,然后运行你的最后两行,一切都应该工作。

+4

是否没有办法创建一个新的回购(在github.com上)从终端? – skube 2014-07-02 15:11:30

0

阅读在GitHub Dochttps://help.github.com/articles/create-a-repo/ 文档他们做好记录它。

+0

声明“我也认为你应该使用双引号'git commit -m”第一次提交“'”是不正确的:http://stackoverflow.com/questions/6697753/difference-between-single-and-double- quotes -in-bash – Potherca 2017-02-07 09:43:41

+0

嗨@Potherca我认为你把评论的错误答案。 – 2017-04-02 03:47:56

+0

不,正确的答案。我的评论是在3月11日的编辑中删除的答案中发表的。 – Potherca 2017-04-02 15:35:20

3

首先,尝试混帐推前这样做的权利:

git pull repo branch 

然后尽量做到以下几点:

$ git init --bare yourreponame.git 

然后你在做什么之前:

touch README 

git add README 

git commit -m 'first commit'

git remote add origin https://github.com/username/Hello-World.git

git push origin master

+0

我用Postman创建了一个存储库,然后使用命令'git remote add origin ',然后按下。谢谢。我想补充一点,命令中单词的顺序很重要! – mihkov 2017-06-15 19:41:46

0

我认为这是可行的。

你可以把它使用curl(如果你使用的是Windows,你必须安装它)

curl -u USER https://api.github.com/user/repos -d '{ "name": "REPO" }' 

确保你的GitHub用户名替换用户和回购和库的名字你想要分别创建

它要求输入密码,输入你的github管理员密码,你很好走。

由詹姆斯·巴尼特在这里https://teamtreehouse.com/community/how-does-one-add-a-repository-to-github-using-git-commandline-calls-only

3

我创造了这个bash的文件自动做这一切其实回答。

#!/bin/sh 
reponame="$1" 
if [ "$reponame" = "" ]; then 
read -p "Enter Github Repository Name: " reponame 
fi 
mkdir ./$reponame 
cd $reponame 
curl -u USERNAME https://api.github.com/user/repos -d "{\"name\":\"$reponame\"}" 
git init 
echo "ADD README CONTENT" > README.md 
git add README.md 
git commit -m "Starting Out" 
git remote add origin [email protected]:USERNAME/$reponame.git 
git push -u origin master 

那么如何:

复制上面的代码。将其保存为NAME.sh,将其添加到PATH中。重新启动终端或打开一个新的终端。

$ NAME newreponame 
$ NAME 
$ Enter Github Repository Name: 

谢谢。

相关问题