コンピュータを楽しもう!!

今、自分が面白くていろいろやってみたことを書き綴りたいと思います。連絡先はtarosa.yでgmail.comです。

githubにソースを登録する

前回の続きです。gitの導入とgithubにアカウントを作ったので、githubにソースを登録してみたいと思います。
今作成しているAndroidとPIC ADK Miniboardを使ったロボット制御プログラムを1つ登録してみたいと思います。ソースはLuaridaで書いています。プログラムはロボット方位磁石です。必ずロボットが北を向くプログラムです。

Gitに設定を登録する

githubにソースを登録するに当たり、Gitの方で先ず初期設定をします。
ユーザ名とe-mailアドレスを登録します。このユーザ名はgithubに登録したnameと同じものにします。

$ git config --global user.name "Tarosa"
$ git config --global user.email "□□□□@gmail.com"

確認します。

$ git config user.name
Tarosa
$ git config user.email
□□□□@gmail.com

githubのユーザ名を設定します。

$ git config --global github.user tarosay

githubのtokenを設定します。

$ git config --global github.token xxxxxxxxxxxxxxxxxxxxxxxxxxx

tokenの値はAccount SettingsのAccount Settingdにあります。

次に、githubでの操作に入ります。

githubリポジトリを作る

「New Repository」ボタンを押します。上で書いていますが、githubのnameはアルファベットの方が良さそうです。「たろサ」から「Tarosay」に変更しました。

新しいリポジトリを作る画面になります。Project NameにRobot Compassと入力して、「Create Repository」ボタンを押します。

そうすると、下のような表示が出ます。

Global setup:
 Set up git
  git config --global user.name "Tarosa"
  git config --global user.email xxxxxxxxx@gmail.com

Next steps:
  mkdir Robot-Compass
  cd Robot-Compass
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin git@github.com:tarosay/Robot-Compass.git
  git push -u origin master

Existing Git Repo?
  cd existing_git_repo
  git remote add origin git@github.com:tarosay/Robot-Compass.git
  git push -u origin master

Importing a Subversion Repo?
  Click here

When you're done:
  Continue

msysGitでの操作

上の表示に従って、リポジトリをコミットしたいと思います。msysGitを開いて入力していきます。
最初のGlobal設定は終了しているので飛ばします。次にリポジトリを取得するフォルダを作ります。どこでもいいのですが、とりあえず /c/msysgit/の下に作りました。

$ mkdir Robot-Compass
$ cd Robot-Compass/

初期化して、.gitフォルダを生成します。

$ git init
Initialized empty Git repository in c:/msysgit/Robot-Compass/.git/

とりあえずREADMEファイルを作ります。

$ touch README

addするとgitにファイルとして認識されるようです。

$ git add README

commitするとgitに登録されるようです。お尻にテキストを入れないと、いきなりviが立ち上がって入力を共用されます。ビックリした・・・。

$ git commit -m 'first commit'
[master (root-commit) 38bc6d3] first commit
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README

git@github.comをリモート操作して、tarosay/Robot-Compass.gitをaddします。

$ git remote add origin git@github.com:tarosay/Robot-Compass.git

masterブランチに対して(として?)、pushすることでgithubに登録されます。

$ git push -u origin master
Enter passphrase for key '/c/Users/□□□/.ssh/id_rsa':
Counting objects: 3, done.
Writing objects: 100% (3/3), 206 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:tarosay/Robot-Compass.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

これで、空っぽのリポジトリが出来上がりました。

ソースを登録します

リポジトリにソースを登録します。/c/msysgit/Robot-Compass/フォルダ内にrbcompass.luaをコピーしました。リポジトリに登録したいソースはフォルダ毎すべて持ってきても構いません。
新規にファイルをコピーしたので、ファイルをaddします。新規ファイルはすべてaddするので、ワイルドカードで一気にaddしてしまいます。

$ git add *
warning: LF will be replaced by CRLF in rbcompass.lua.
The file will have its original line endings in your working directory.

1つだけなので、メッセージはこれだけです。
ステータスを見てみます。

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   rbcompass.lua
#

これをコミットします。コミットすれば、いつでもgithubに上げられます。

$ git commit -m 'second commit'
[master c6e925b] second commit
warning: LF will be replaced by CRLF in rbcompass.lua.
The file will have its original line endings in your working directory.
 1 files changed, 181 insertions(+), 0 deletions(-)
 create mode 100644 rbcompass.lua

aオプションを付けた場合は、更新のあったファイルのみをコミットしてくれます。mオプションを省略すると、viエディタが立ち上がります。

$ git commit -a

最後に、githubにpushします。

$ git push -u origin master
Enter passphrase for key '/c/Users/□□□/.ssh/id_rsa':
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 2.24 KiB, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:tarosay/Robot-Compass.git
   xxxxxx..xxxxx  master -> master
Branch master set up to track remote branch master from origin.

これで、githubにソースを登録することができました。gitのコマンドの使い方は、おいおい勉強して行こうと思います。