2012-07-27 16 views
17

私のマシンからgit bashを使って新しいリポジトリを作成する方法は?git bashを使ってGithubで新しいリポジトリを作成するには?

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

答えて

17

あなたはgithubの上のレポを作成することはできませんgit bashを使ってgitとgithubは別のものです。 Githubはコードをホストして共同作業をするプラットフォームで、gitはバージョン管理ツールです。あなたはウィキペディアの記事(githubgit)についてもっと詳しく読むことができます。

しかし、端末を使ってgithubリポジトリを作成する場合は、github apiとcurlを使用して行うことができます。

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

5

おそらくgithubの上のレポを作成する最も簡単な方法は、どこか前のこのラインである:

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

https://github.com/newに行きますgithubでリポジトリを作成し、最後の2行を実行すればすべてがうまくいくはずです。

+4

新しいレポを作成する方法はありませんか? (github.comで)端末から? – skube

0

読みますGitHub Dochttps://help.github.com/articles/create-a-repo/ 彼らはそれを文書化して良い仕事をしています。

+0

"二重引用符を使用したはずです。' git commit -m "first commit" '"は間違っています:http://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes -in-bash – Potherca

+0

こんにちは@Potherca私はあなたが間違った答えにコメントを置くと思います。 –

+0

いいえ、正解です。私のコメントは、3月11日のあなたの編集で削除された解答のステートメントに対処しました。 – Potherca

3

まず、Gitのプッシュする前にこの権利をやろう:

git pull repo branch 

その後、次のやろう:

touch README 

git add README 

$ git init --bare yourreponame.git 

を次に前に、あなたは何をしていたかやります

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

0

私はそれがなんとかだと思います。

あなたはカール使用してそれを行うことができます(Windowsである場合、あなたはそれをインストールする必要があります)

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

あなたのgithubのユーザ名とリポジトリあなたの名前のユーザーとREPOを交換することを確認しますそれぞれ作成したい

パスワードを尋ねて、あなたのgithub管理者パスワードを入力してください。

は実際に私が自動的にそれをすべて行うために、このbashのファイルを作成している、ここでhttps://teamtreehouse.com/community/how-does-one-add-a-repository-to-github-using-git-commandline-calls-only

3

ジェームズ・バーネットによって答えました。

は上記のコードをコピー:どのように

#!/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: 

ありがとうございます。

関連する問題