GitHubとGit

  • 投稿者:
  • 投稿カテゴリー:未分類

「GitHub実践入門」を購入した、いろいろやってみたことのまとめ

GitHubメリット

・タスク管理やバグ報告をIssueを利用してやりとりできる
・Pull Request(Gitリポジトリに対して、変更したソースを追加するようにリクエストすること)が利用できる
・OSSはGitHubを利用していることが多く、他のプロジェクトにも参画しやすくなる

Gitについて

Linuxのソースコード管理のために開発された
分散型バージョン管理システム
集中型:リポジトリをサーバに集中させて配置する、そのためリポジトリは1つだけ。サーバに繋がらなければ何もできず、競合が発生しやすい
分散型:ユーザごとにリポジトリを配置する、ユーザ間でpushやpullが可能であり、サーバに繋がらずとも自端末だけで作業可能

root@hostname:/home/shimizu# git config --global user.name "shimizu hiroaki"
root@hostname:/home/shimizu# git config --global user.email "shimizu.r.hiroaki@gmail.com"
### Git が自動的に大半の出力に色づけするようにしておく ###
root@hostname:/home/shimizu# git config --global color.ui true 
root@hostname:/home/shimizu# cat /root/.gitconfig 
[user]
        name = shimizu hiroaki
        email = shimizu.r.hiroaki@gmail.com
[color]
        ui = true

GitHub利用前の準備

root@hostname:/home/shimizu# ssh-keygen -t rsa -C shimizu.r.hiroaki@gmail.com 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): key
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in key.
Your public key has been saved in key.pub.
The key fingerprint is:
7a:f0:75:7e:91:84:2a:9b:78:1a:9b:f9:22:44:7e:ef shimizu.r.hiroaki@gmail.com
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|           .     |
|          . .    |
|      . S .+..   |
|  .    S .ooo    |
| o      o.  ...  |
|  o o .*o   .. . |
+-----------------+

root@hostname:/home/shimizu# ssh-add key
Identity added: key (key)

### 以下をGitHubに登録する ###
root@hostname:/home/shimizu# cat key.pub 
ssh-rsa 
...............
shimizu.r.hiroaki@gmail.com

GitHubアカウントを取得し、先ほどの公開鍵を[Add SSH key]から登録する
Screenshot 2014-12-07 at 22.58.31

### GitHubとの認証テスト ###
root@hostname:/home/shimizu# ssh -T git@github.com
Hi shimizuhiroaki! You've successfully authenticated, but GitHub does not provide shell access.

GitHubを使ってみる

リポジトリを作成する
Screenshot 2014-12-07 at 23.37.35

特定のフレームワークを利用時は、.gitignoreを設定すると特定のファイルをバージョン管理から除くため便利
Screenshot 2014-12-07 at 23.39.56

ユーザ名/リポジトリ名 でアクセス可能
https://github.com/shimizuhiroaki/bash
Screenshot 2014-12-07 at 23.42.47

root@hostname:/home/shimizu# mkdir github
root@hostname:/home/shimizu# cd github/
root@hostname:/home/shimizu/github# git clone git@github.com:shimizuhiroaki/bash.git
Cloning into 'bash'...
Warning: Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hosts.
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
root@hostname:/home/shimizu/github# cd bash/
root@hostname:/home/shimizu/github/bash# ls -al
合計 16
drwxr-xr-x 3 root root 4096 12月  7 23:47 .
drwxr-xr-x 3 root root 4096 12月  7 23:47 ..
drwxr-xr-x 8 root root 4096 12月  7 23:47 .git
-rw-r--r-- 1 root root   22 12月  7 23:47 README.md

root@hostname:/home/shimizu/github/bash# touch sample
root@hostname:/home/shimizu/github/bash# git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       sample
nothing added to commit but untracked files present (use "git add" to track)
### コミットする前の準備。ワークツリーからインデックスにファイルを登録する ###
### すべてのファイルを登録する場合は git add .###
root@hostname:/home/shimizu/github/bash#  sample 
### コミットする ###
root@hostname:/home/shimizu/github/bash# git commit sample -m "add sample file"
[master a8c57b9] add sample file
 1 file changed, 1 insertion(+)
 create mode 100644 sample

root@hostname:/home/shimizu/github/bash# git log
^[[33mcommit a8c57b9866e78f3aac4e7429971293a3df4e51ef^[[m
Author: shimizu hiroaki <shimizu.r.hiroaki@gmail.com>
Date:   Sun Dec 7 23:53:08 2014 +0900

    add sample file

^[[33mcommit f2bc27f60188cdd9ba656831b1b623cc8c7477ee^[[m
Author: shimizuhiroaki <shimizu.r.hiroaki@gmail.com>
Date:   Sun Dec 7 23:42:17 2014 +0900

    Initial commit
root@hostname:/home/shimizu/github/bash# git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)

### GitHubのリポジトリに登録する ###
root@hostname:/home/shimizu/github/bash# git push
Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 292 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:shimizuhiroaki/bash.git
   f2bc27f..a8c57b9  master -> master

参考URL

分散バージョン管理システムGit入門
http://www.itmedia.co.jp/enterprise/articles/0902/09/news019.html
itHubを使ってみよう!導入と簡単な流れ、よく使うコマンドなど。
http://wp.yat-net.com/?p=3874
サルでもわかるGit入門
http://www.backlog.jp/git-guide/intro