- 2015/9/11(金)19:30
- gitコマンドを入力しながら基礎から学ぶ勉強会
- http://www.zusaar.com/event/9987007
- #fukuoka_cam_study
# 作業ディレクトリを作成します。
mkdir study_git
# 移動します
cd study_git
# gitの状態を確認
git status
## fatal: Not a git repository
## (or any of the parent directories): .git
# 初期化コマンド
git init
## Initialized empty Git repository in
## /Users/xxx/Documents/work/gitstudy/study_git/.git/
# 確認
ls -a
## . .. .git
## (.gitが出来てる!)
# gitの状態を確認
git status
## gitの管理が始まったよ
## On branch master
##
## Initial commit
##
## nothing to commit (create/copy files and use "git add" to track)
# 一旦 gitの管理を外れてもう一回作り直りしてみる
rm -rf .git/
# gitの管理から外れることを確認しよう
git status
## fatal: Not a git repository (or any of the parent directories): .git
# 次章にそなえてもう一回作成する
git init
git status
- gitは .git があるディレクトリ(サブディレクトリも)以下を監視します。
- git status で 状態を確認しましょう
# hello.txtを追加(テキストエディタで編集)
- gedit hello.txt
- vim hello.txt
- Windowsのメモ帳などで hello.txt 開く
# 下記テキストを記入
## konchiha sekai
# 確認
git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# hello.txt
#
# nothing added to commit but untracked files
# present (use "git add" to track)
## ☆ Untracked files とは ..
# 新しく追加したファイルをgitに教える
## ファイルの追跡を開始する
git add hello.txt
# 確認
git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: hello.txt
## ☆ unstage とは..
# 変更履歴の登録
## ファイルのスナップショットを歴史に書き込む
git commit -m "hajimete commit"
# [master (root-commit) a2c18d9] hejimete commit
# 1 file changed, 1 insertion(+)
# create mode 100644 hello.txt
# 確認
git status
# On branch master
# nothing to commit, working directory clean
# 確認
git log
# commit 履歴の位置を示す番号
# Author: コミットした人の名前 <メール>
# Date: Mon Sep 7 06:48:35 2015 +0900
#
# hejimete commit
#
# 詳細に確認する
git log -p
# ざっくり確認する
git log --oneline
###
### 復習
###
# 追加してみよう
aiueo.txt
## aiueo aiueo
git add aiueo.txt
git status
git commit -m "add aiueo.txt"
git status
git log
# 追加してみよう2
test.txt
## test test
git add test.txt
git status
git commit -m "add test.txt"
git status
git log
- コミット対象にする為に git add する
- add されたファイルは stage の上に登録される
- stage の上に登録されているものが commit対象になる
- git commit で addされたものをコミットする
- git log でコミット履歴を表示する
# hello.txt の末尾に1行追加します
# 何かテキストエィデタで足す
## konchiha sekai
## konbanha
# 変更内容を確認する
git diff
# diff --git a/hello.txt b/hello.txt
# index f9f5e77..11e5cfd 100644
# --- a/hello.txt
# +++ b/hello.txt
# @@ -1 +1,2 @@
# konchiha sekai
# +konbanha
# (END)
## 追加内容の左横に + がある
# 状態を確認する
git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: hello.txt
#
# no changes added to commit (use "git add" and/or "git commit -a")
#
## ☆ modified ってなってる
# 変更を登録
git add hello.txt
git commit -m "update hello.txt"
git log
### 復習 ###
hello.txt に何か加えてコミットを2回
## example hogehoge
## example fugafuga
git add hello.txt
git commit -m "update2 hello.txt"
git log
- 修正もコミット対象にする為に git add する
- add されたファイルは stage の上に登録される
- stage の上に登録されているものが commit対象になる
- git commit で addされたものをコミットする
- git log でコミット履歴を表示する
# 作業場所(ブランチ)一覧を確認しよう
git branch
# * master
## ☆ 今いるブランチの左に * がつきます
# 別の作業場所を作ってみましょう
git branch apple
# 一覧で確認
git branch -v
# apple 8550a2f update3 hello.txt
#* master 8550a2f update3 hello.txt
## * マークの位置でmasterにいること
## コミット番号が同じなので
## masterと appleは同じであることがわかる
# 作業場所(apple)に移動
git checkout apple
git branch
# * apple
# master
## ☆ appleに移動したことがわかります
# hello.txt を更新しましょう
# konchiha を konbanwa に更新
gedit hello.txt
vim hello.txt
git diff
# diff --git a/hello.txt b/hello.txt
# index bbcf46f..5381f68 100644
# --- a/hello.txt
# +++ b/hello.txt
# @@ -1,4 +1,4 @@
# -konchiha sekai
# +konbanwa sekai
# konbanha
# hogehoge
# fugafuga
git add hello.txt
git commit -m "update hello in apple"
git log
# 最初の作業場所(master)ブランチに戻る
git checkout master
# Switched to branch 'master'
# appleで更新した内容を master に反映する
# まず確認
git diff apple
# diff --git a/hello.txt b/hello.txt
# index 5381f68..bbcf46f 100644
# --- a/hello.txt
# +++ b/hello.txt
# @@ -1,4 +1,4 @@
# -konbanwa sekai
# +konchiha sekai
# konbanha
# hogehoge
# fugafuga
## ☆ appleの修正点と masterの内容の違いがわかる
# appleの変更点をmasterに反映(マージ)する
git merge apple
# Updating 8550a2f..e06850f
# Fast-forward
# hello.txt | 2 +-
# 1 file changed, 1 insertion(+), 1 deletion(-)
# appleの作業内容がmasterに反映されていることを確認
git log
### 復習 ###
# orange ブランチで作業してmasterに反映させよう
git branch orange
git checkout orange
git branch
# apple
# master
# * orange
# hello.txtを変更
# 3行目4行目を消すなど
vim hello.txt
git diff
# diff --git a/hello.txt b/hello.txt
# index 5381f68..5692d36 100644
# --- a/hello.txt
# +++ b/hello.txt
# @@ -1,4 +1,2 @@
# konbanwa sekai
# konbanha
# -hogehoge
# -fugafuga
git add hello.txt
git commit -m "update hello.txt in orange"
git log
git checkout master
git merge orange
git log
GitHubの画面をプロジェクタで写しながら説明する予定 sample という名前のプロジェクトを作成します。
-
右下緑の "+ New Repository" ボタンをクリック
-
Repository name に sample
-
create repository
-
"SSH"ボタンを押してください
-
"…or create a new repository on the command line"通りにコマンドを打ちます
☆ git remote add でリモート(インターネット上のサーバ)の場所を登録してます ☆
-
GitHubの画面で自分が作ったプロジェクトができてます
-
プロジェクトにファイルを追加してみましょう
# hello.txt の追加
vim hello.txt
## 例
## konchiha sekai
git add hello.txt
git commit -m "add hello.txt"
git log
## リモートリポジトリ(GitHub)への接続先を確認する
git remote -v
# origin git@github.com:xxx/sample.git (fetch)
# origin git@github.com:xxx/sample.git (push)
## リモートリポジトリ(GitHub)への変更を送る
### origin ← git@github.com:xxx/sample.git
### :の左 ローカル(自分のPC)のリポジトリ
### :の右 リモート(GitHub)のリポジトリ
git push origin master:master
# Counting objects: 3, done.
# Delta compression using up to 4 threads.
# Compressing objects: 100% (2/2), done.
# Writing objects: 100% (3/3), 295 bytes | 0 bytes/s, done.
# Total 3 (delta 0), reused 0 (delta 0)
# To git@github.com:xxx/sample.git
# xxxxxxx..xxxxxxx master -> master
GitHubの画面でファイルが追加されていることを確認しましょう
## 復習
# hello.txt を変更して GitHubに変更をおくりましょう
vim hello.txt
git add hello.txt
git commit -m "update hello.txt"
git log
git remote -v
git push origin master:master
-
GitHubの画面で参加したいプロジェクトのページを開きます
-
右上の "Fork"ボタンを押します
-
Where should we fork this repository? と聞かれますので自分を選びます
-
自分のリポジトリにForkしたリポジトリができます
自分の名前/プロジェクト名
forked from Forkした相手の名前/プロジェクト名
- 右下のURLで自分のPCの中に git のフォルダを作ります
git clone git@github.com:自分の名前/プロジェクト名.git
# Cloning into 'プロジェクト名'...
# remote: Counting objects: 3, done.
# remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
# Receiving objects: 100% (3/3), done.
# Checking connectivity... done.
cd プロジェクト名
# gitのフォルダができていることを確認
git status
# On branch master
# Your branch is up-to-date with 'origin/master'.
# nothing to commit, working directory clean
- ブランチを作ってファイルを修正してみましょう
# apple ブランチ(作業場所)を作る
git branch apple
# 作った作業場所に移動する
git checkout apple
# Switched to branch 'apple'
# appleにいることを確認
git branch -v
# * apple 90f75e4 first commit
# master 90f75e4 first commit
# statusでもわかる
git status
# On branch apple
# nothing to commit, working directory clean
# README.md を修正
vim README.md
# 例)
# # sample999
#
# hello hello
git diff
git add README.md
git commit -m "update README"
git log --oneline
# 5579ff5 update README
# 90f75e4 first commit
# ☆自分のリモートリポジトリに送る☆
# 接続先確認
git remote -v
# origin git@github.com:xxx/yyyy.git (fetch)
# origin git@github.com:xxx/yyyy.git (push)
# 自分のPCの中の(ローカルリポジトリの中の)
# appleブランチをリモート先のappleブランチに送る
git push origin apple:apple
-
GitHubのページに "Compare & pull request" ボタンができるので押す
-
プルリクエスト(変更内容をFork元の人に送る)画面になりますので "Create pull Request" を押す
-
Fork元の人に修正が飛んでいきます。
-
Fork元の人は右側の Pull requestsを押します
-
先ほど送ったプルリクエストが Fork元に届いていますので "Merge pull request"ボタンを押します そうすると送られてきた修正が取り込まれます
-
もう一回修正を送る
# 最新のソースをFork元から取得するため
# Fork元を remote 先に追加する
# Fork元の名前を upstream にすることが多い気がします
git remote add upstream git@github.com:Fork元の人の名前/プロジェクト名.git
# 確認
git remote -v
# origin git@github.com:自分の名前/プロジェクト名.git (fetch)
# origin git@github.com:自分の名前/プロジェクト名.git (push)
# upstream git@github.com:Fork元の人の名前/プロジェクト名.git (fetch)
# upstream git@github.com:Fork元の人の名前/プロジェクト名.git (push)
# masterブランチ(最初の作業場所)に戻る
git checkout master
# ログがちょっと古い
git log
# Fork元から最新ソースを取得
git fetch upstream
# remote: Counting objects: 1, done.
# remote: Total 1 (delta 0), reused 1 (delta 0), pack-reused 0
# Unpacking objects: 100% (1/1), done.
# From github.com:Fork元の人/プロジェクト
# * [new branch] master -> upstream/master
# 取ってきた最新ソースと自分のmasterソースを混ぜます
git merge upstream/master
# 最新のソースを撮ってきていることをログで確認
git log
# 最新ソースを自分のリモートリポジトリにも保存
git push origin master:master
### 復習 ###
git branch orange
git checkout orange
git branch -v
# README.md を修正
vim README.md
# 例)
# # sample999
#
# hello hello
# foge foge
git commit -m "update fogefoge"
git push origin orange:orange
## ブラウザで開いてプルリクエストを送る
- いらなくなったブランチを消す
git branch -d apple
# Deleted branch apple (was 5579ff5).
git push origin :apple
# To git@github.com:自分の名前/プロジェクト名.git
# - [deleted] apple
git初心者への道 - お仕事で困らないレベルまでググっとします。
https://gist.github.com/yatemmma/6486028
Git初心者に捧ぐ!Gitの「これなんで?」を解説します http://kray.jp/blog/git-why-explanation/
git diff の使い方がほんの少し理解できた
http://d.hatena.ne.jp/murank/20110320/1300619118
今さら聞けないgit pushコマンド http://shoma2da.hatenablog.com/entry/2014/03/08/234523
git push -u
オプションの意味 http://qiita.com/ironsand/items/6c301fef730d53f35bc3
-
CentOS6.7 (Virtual box/Windows)
-
teminal: Monospace 22
-
解像度: 1920 x 1080