2012-07-27 34 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: 

謝謝。

相關問題