LoginSignup
2
6

More than 5 years have passed since last update.

GitHub入門

Last updated at Posted at 2018-01-05

目的

GitHubに入門して、初めてlocal, remote repositoryを作成して投稿するまでの流れを備忘録を兼ねて書きます。

Remote repositoryを作成する

まずは、GitHubのページでrepositoryを作成します。GitHubにアカウントを持っていない人は登録しましょう。

  1. 画面右上のプラスボタンをクリックして、「New repository」をクリックします。
  2. Repository Nameを記入します。
  3. Public, Privateを選択する部分がありますが、無料版ではPublicしか選べません。
  4. 更にその下に、ReadMeファイルを作るか、などありますがチェックはしないでおきます。最初、ReadMeファイルを作成したために、エラーが出てしまい苦労しました。

作成すると、
Screenshot at 2018-01-05 11-01-36.png

このような画面が出ます。赤枠で囲んだ部分はrepositoryのアドレスで、このあとlocal repositoryとつなげるときに必要になりますのでコピーしておきます。

Local repositoryを作成する

次に、パソコン上にlocal repositoryを作成します。コマンドライン上で、

$ mkdir git_test    #新しいフォルダを作成
$ cd git_test    
$ git init    #local repositoryを作成

これでlocal repositoryが作成されました。この中にファイルを作成していきます。ここでは例としてtest.txtという簡単なテキストファイルを作りました。これを追加するには

$ git add test.txt 
$ git commit -m "This is a test file."    #コメント

などとします。

GitHub上にPushする

では、local repositoryをGitHubのRemote repositoryにPushします。ここで、先ほど確認したRemote repositoryのアドレスを使います。

$ git remote add origin https://"アドレス"
$ git push -u origin master

これでPush完了です。

Remote repositoryを作成するときに、ReadMeファイルを作ってしまうと、Pushするときに

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/ /test.git'
ヒント: Updates were rejected because the remote contains work that you do
ヒント: not have locally. This is usually caused by another repository pushing
ヒント: to the same ref. You may want to first integrate the remote changes
ヒント: (e.g., 'git pull ...') before pushing again.
ヒント: See the 'Note about fast-forwards' in 'git push --help' for details.

なるエラーが出てきて、Pushできません。理由は謎です

2
6
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
6