GitHubにリポジトリを作成してみる
VirtualBoxにCentOSをとりあえずインストール
の続き。
GitHubにリポジトリを作成してみる。
ついでにファイルも追加してみる。
GitHubでリポジトリを作成
GitHubのページ(https://github.com/)を開いて、
[New repository]のボタンを押す。
リポジトリ名を入力し、
[Initialize this repository with a README]
にチェックを入れて、リポジトリを作成する。
今回は「sample」という名前でリポジトリを作成する。
[Initialize this repository with a README]にチェックを入れないと、 リポジトリを新規に作成?するために下記のようなコマンドを 打たないといけなくなるみたい(よく分かっていません) touch README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/ユーザー名/sample.git git push -u origin master
以上で、リポジトリが作成される。
Gitのインストール
Gitがインストールされてないのでインストールしておく。
$ sudo yum -y install git
Gitでファイルを追加してみる
$ git clone https://github.com/ユーザー名/sample.git
cloneするリポジトリのURLは、GitHubのリポジトリの上記の画面の右下にある
[HTTPS clone URL]で参照できます。
cloneされたので、ディレクトリに移動。
$ cd sample
追加するファイルを適当に作成する。
$ vi hello.txt
ファイルをaddし、commitする。
$ git add hello.txt $ git commit -m 'ファイルを追加'
$ git push
はずだが、なんかエラーがでた。
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/yk5656/sample.git/info/refs fatal: HTTP request failed
下記のサイトを参考にして
githubにアップロードする【CUI編】 | クラウドインフラ構築記 http://www.totalsolution.biz/github%E3%81%AB%E3%82%A2%E3%83%83%E3%83%97%E3%83%AD%E3%83%BC%E3%83%89%E3%81%99%E3%82%8B%E3%80%90cui%E7%B7%A8%E3%80%91/
configを開いて、「ユーザー名@」を付け足す。
$ vi .git/config
url = https://ユーザー名@github.com/yk5656/sample.git
あらためてpushする。
$ git push