LoginSignup
39
42

More than 5 years have passed since last update.

GitHubに入門(その1)

Posted at

GitHubをこれまでに触ったことがなかったので、
GitHub実践入門」を参考に実施した際のメモ。

  • OS:Windows 7 Professional 64bit
  • Git:1.8.3.msysgit.0

全体の流れ

  1. GitHubにアカウントを登録
  2. ローカルでssh-keygenを実行して鍵を作成(パスフレーズも設定)
  3. GitHubのページで公開鍵(~/.ssh/id_rsa.pub)の内容を貼り付けてSSH Keyを登録
  4. リポジトリの作成
  5. 作成したリポジトリをclone
  6. コードの作成
  7. コミット(git commit)
  8. push(git push)
  9. ブラウザでpushしたファイルが参照できるかを確認

公開鍵の登録後、動作確認時にエラー

公開鍵の登録後、GitHubと認証しようとした際にエラーが発生。

$ ssh -T git@github.com
The authenticity of host 'github.com (192.30.252.131)' can't be established.
RSA key fingerprint is <フィンガープリント>.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.131' (RSA) to the list of known hosts.
Permission denied (publickey).

ググったところ、ssh-addで秘密鍵を追加すればよいとのこと。
$ ssh-add /C/Users/<ユーザ名>/.ssh/id_rsa
Could not open a connection to your authentication agent.

エラーが出る。

さらにググったところ、事前にeval `ssh-agent`を実行しないといけない模様。

$ eval `ssh-agent`
Agent pid 1940

$ ssh-add /C/Users/<ユーザ名>/.ssh/id_rsa
Enter passphrase for /C/Users/<ユーザ名>/.ssh/id_rsa:<パスフレーズ>
Identity added: /C/Users/<ユーザ名>/.ssh/id_rsa (/C/Users/<ユーザ名>/.ssh/id_rsa)

$ ssh -T git@github.com
Hi <ユーザ名>! You've successfully authenticated, but GitHub does not provide shell access.

無事に動作確認が完了した。

ssh-agentは認証エージェントと呼ばれるもので、パスフレーズを保持するプロセス。ssh-agentを実行すると実行したいコマンドが出力されるので、eval `ssh-agent`としてあげる必要がある。
ssh-addはパスフレーズを登録するためのコマンド。

git push時に警告発生

下記のような警告メッセージが出力された。

$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Username for 'https://github.com':

git configでpush.defaultに値を設定する必要がある。設定する値や詳細についてはここに記載されている。

$ git config --global push.default matching

$ git push
Username for 'https://github.com': <ユーザ名>
Password for 'https://<ユーザ名>@github.com':<パスフレーズ>
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 361 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/<ユーザ名>/Hello-World.git
   8d7b8fc..77fcef3  master -> master
39
42
0

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
39
42