14
16

More than 5 years have passed since last update.

さくらVPS(CentOS 6.4)とGitHubを繋ぐ (さくらVPSからGitHubにデータをPush) ( Webサーバー構築四苦八苦 5th Day, GitHub 編 )

Last updated at Posted at 2013-11-15

まずはGitHub側の設定

リポジトリを作成

作成すると、リポジトリのページ内に、リポジトリのクローンURLが表示されます。
例: git@github.com:{hostname}/{project_name}.git #これあとで使います。

サーバーでの鍵作成

/home/{hostname}/.ssh
$ ssh-keygen -r rsa
 # デフォルトの名前(id_rsa, id_rsa.pub)名前で作るといいです。そうじゃないと、git/configとかに鍵ファイルの指定が必要になります。

$ pbcopy < id_rsa.pub # 公開鍵の中身をコピーしておきます。

GitHubでの鍵の設定

GitHub Webページの「User settings」「SSH Key」へ。
「Add SSH key」に進んでクリップボートにコピーした公開鍵を貼り付けます。

確認

サーバーに戻って作業します。
鍵の設定がうまくいっているか確認します

$ ssh -l git -i ~/.ssh/id_rsa github.com 
The authenticity of host 'github.com (192.30.252.130)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.130' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0
Hi su3! You've successfully authenticated, but GitHub does not provide shell access.
                                                                                    Connection to github.com closed.

Gitを使います

$ cd {project_name}
$ git init          # 初期化
$ touch README.md    

# .gitignoreに.DS_Store,database.ymlを追加
$ vim .gitignore     # Githubに上げたくないものを指定します。

## ファイルをコミット
$ git add .         # まずは全ファイルをあげます。
$ git commit -m "initial commit"         #コメントは適切なものを

## リモートのリポジトリを追加
$ git remote add origin git@github.com:{account_name}/{project_name}.git     # リモートリポジトリを追加
$ git remote    # 追加されたリモートリポジトリを確認
$ git push origin master     # データを送信します
14
16
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
14
16