2015年3月29日日曜日

RaspberryPIでgitを使ってみる。

RaspberryPIでgitを使ってみる。

1.ユーザー名、メールアドレスの設定

 $ git config --global user.name "user"  
 $ git config --global user.email mail.com

2.SSHの鍵の設定

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/pi/.ssh/id_rsa):← Enter
Created directory '/home/pi/.ssh'. ← ~/.ssh がない場合、ディレクトリを作成します
Enter passphrase (empty for no passphrase): ← パスフレーズを入力します
Enter same passphrase again: ← もう一度パスフレーズを入力します
Your identification has been saved in /home/pi/.ssh/id_rsa.
Your public key has been saved in /home/pi/.ssh/id_rsa.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:pi@raspberrypi
The key's randomart image is:

「./ssh/id_rsa.pub」の内容を
githubのpersonal settingの「SSH Public Keys」に登録する

3.SSHで接続してみる。

$ ssh -l git -i ~/.ssh/github_id_rsa github.com
:
:
Enter passphrase for key '/home/pi/.ssh/id_rsa : さっきのパスフレーズ
:
Connection to github.com closed.
$ vi ~/.ssh/config
Host github.com
 HostName      github.com
 IdentityFile  ~/.ssh/github_id_rsa
 User          git
$ ssh github.com

4.リポジトリからクローンする。
 すでにホームページでリポジトリは作ってあったので、クローンをしてファイルをダウンロードする。

$ git clone リポジトリのurl 

githubと同じフォルダができ、ファイルがダウンロードされる。別のフォルダ(AAA)にダウンロードしたい場合は以下とする。

$ git clone リポジトリのurl AAA

5.新しいファイルをリポジトリに追加

$ git add filename
$ git add directoryname

6.変更したファイルをローカルリポジトリにコミット

$ git commit -m 'something changed'

$ git commit -am “-aオプションを付けるとaddとcommitを一緒にできる”

7.ローカルリポジトリの変更をリモートリポジトリに反映

$ git push
Username for 'https://github.com' : xxx
Password for 'https://xxxxx : yyy

まだよくgitの使い方を理解できていないですが、変更内容をgithubに登録できました。

参考
Ubuntuでgithubを使う
ターミナルからgithubのリポジトリにアクセスする設定(sshの設定)
いまさら聞けないgitの使い方
githubに既にあるプロジェクトからcloneして編集してpushする手順

0 件のコメント :

コメントを投稿