Kohei Nozaki's blog 

GitHubで遊ぶ


Posted on Tuesday Feb 11, 2014 at 11:16AM in Technology


環境

  • git version 1.8.3.4 (Apple Git-47)
  • OS X 10.9.1

前提条件

GitHubのアカウント登録とssh公開鍵登録は終わっているものとする。

参考文献を見ると専用の鍵ペア作ったりしてたけど面倒なので適当なid_rsa.pubを放り込んどいた。

Repositoryを作る

[2]に書いてあるけど

  1. ホーム画面でNew Repositoryを押す

  2. Repository nameとDescriptionを適当に埋めてCreate repositoryを押す

  3. つくられた

CLIからいじってみる

cloneしてみる

kyle-no-MacBook:gitprac2 kyle$ git clone git@github.com:lbtc-xxx/hello.git
Cloning into 'hello'...
Warning: Permanently added the RSA host key for IP address '192.30.252.129' to the list of known hosts.
warning: You appear to have cloned an empty repository.
Checking connectivity... done
kyle-no-MacBook:gitprac2 kyle$ ls -ld hello
drwxr-xr-x+ 3 kyle  staff  102  2 11 11:28 hello
kyle-no-MacBook:gitprac2 kyle$ ls -lR hello
total 80
-rwxr-xr-x+ 1 kyle  staff   452  2 11 11:28 applypatch-msg.sample
-rwxr-xr-x+ 1 kyle  staff   896  2 11 11:28 commit-msg.sample
-rwxr-xr-x+ 1 kyle  staff   189  2 11 11:28 post-update.sample
-rwxr-xr-x+ 1 kyle  staff   398  2 11 11:28 pre-applypatch.sample
-rwxr-xr-x+ 1 kyle  staff  1704  2 11 11:28 pre-commit.sample
-rwxr-xr-x+ 1 kyle  staff  1348  2 11 11:28 pre-push.sample
-rwxr-xr-x+ 1 kyle  staff  4951  2 11 11:28 pre-rebase.sample
-rwxr-xr-x+ 1 kyle  staff  1239  2 11 11:28 prepare-commit-msg.sample
-rwxr-xr-x+ 1 kyle  staff  3611  2 11 11:28 update.sample

hello/.git/info:
total 8
-rw-r--r--+ 1 kyle  staff  240  2 11 11:28 exclude

hello/.git/objects:
total 0
drwxr-xr-x+ 2 kyle  staff  68  2 11 11:28 info
drwxr-xr-x+ 2 kyle  staff  68  2 11 11:28 pack

hello/.git/objects/info:

hello/.git/objects/pack:

hello/.git/refs:
total 0
drwxr-xr-x+ 2 kyle  staff  68  2 11 11:28 heads
drwxr-xr-x+ 2 kyle  staff  68  2 11 11:28 tags

hello/.git/refs/heads:

hello/.git/refs/tags:
kyle-no-MacBook:gitprac2 kyle$ %%%

よくわからないけど何かgitのディレクトリ構造っぽいものができている。

commitしてみる

kyle-no-MacBook:gitprac2 kyle$ cd hello
kyle-no-MacBook:hello kyle$ echo hoge > README.md
kyle-no-MacBook:hello kyle$ git add README.md
kyle-no-MacBook:hello kyle$ git commit -m "first commit"
[master (root-commit) 30ec784] first commit
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
kyle-no-MacBook:hello kyle$ 

この時点ではGitHub側の画面をリロードしても資源が上がったりはしていない。たぶんpushってのをやらないとだめなんだろう。

pushしてみる

kyle-no-MacBook:hello kyle$ 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)

Warning: Permanently added the RSA host key for IP address '192.30.252.130' to the list of known hosts.
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'git@github.com:lbtc-xxx/hello.git'
kyle-no-MacBook:hello kyle$ 

よくわからないけどおこられた。[4]を見ると何やらパラメータが必要っぽいのでよくわからないけど追加してみる

kyle-no-MacBook:hello kyle$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 214 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:lbtc-xxx/hello.git
 * [new branch]      master -> master
kyle-no-MacBook:hello kyle$ 

GitHubのgitのコマンド例が書かれたページをリロードしてみると

何かがアップロードされた。うむ

編集してadd→commit→pushしてみる

kyle-no-MacBook:hello kyle$ echo hogehoge >> README.md 
kyle-no-MacBook:hello kyle$ git add README.md 
kyle-no-MacBook:hello kyle$ git commit -m "second commit"
[master 79e339f] second commit
 1 file changed, 1 insertion(+)
kyle-no-MacBook:hello kyle$ git push origin master
Counting objects: 5, done.
Writing objects: 100% (3/3), 249 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:lbtc-xxx/hello.git
   30ec784..79e339f  master -> master
kyle-no-MacBook:hello kyle$ 

うむ。

参考文献

  1. EclipseでMavenプロジェクトを作ってGithubで管理 - Qiita
  2. ナウなヤングのためのgithub入門講座 -基本機能からdotfiles管理まで- - tumblr
  3. GitHub+Eclipseを使ったプロジェクトのはじめ方 - Archit!!
  4. git - Why can't I push to this bare repository? - Stack Overflow
  5. GitHub for Mac



No one has commented yet.

Leave a Comment

HTML Syntax: NOT allowed