LoginSignup
20
11

More than 5 years have passed since last update.

gitとgithubの連携

Posted at

githubにgitのソースを最初にpushしたいときのメモ

以下2点が前提条件
githubのアカウントをもっている
ローカル環境でgit管理しているソースがある

githubでrepositoryを新しく作るとこのコマンドたたけよって親切に教えてくれる。

echo "# test" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:{github-account}/test.git
git push -u origin master

だけどpushコマンドのときにエラーになった。
git push -u origin master

$ git push -u origin master
The authenticity of host 
~
~
~
Please make sure you have the correct access rights
and the repository exists.

理由はgithubにsshkeyが登録されていなかったから。
なので以下の手順を実行する。
1.ssh鍵のありかを確認する。
$ ls ~/.ssh
2.登録しているメールアドレスを確認する。
$ git config --global user.email
3.公開鍵を作る。
$ ssh-keygen -t rsa -C "メールアドレス"
4.作られた公開鍵をクリップボードに貼り付ける
$ clip < ~/.ssh/id_rsa.pub
5.githubの【settings】-【SSH and GPG keys】で公開鍵登録画面に遷移する
https://github.com/settings/keys
6.右上の【newsshkey】ボタンを押して【key】のテキストエリアにコピーしたsshkeyを貼り付ける
このときtitleはわかりやすければ何でも良い。
7.画面下方の【Add SSH key】ボタンを押して登録完了。
8.コマンドで一度githubに接続確認をする。
$ ssh -T git@github.com

これでgit pushができるようになる。

20
11
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
20
11