Skip to content

Instantly share code, notes, and snippets.

@kauplan
Created December 3, 2017 15:40
Show Gist options
  • Save kauplan/dd5ca488d1986acccea1748ea01291b0 to your computer and use it in GitHub Desktop.
Save kauplan/dd5ca488d1986acccea1748ea01291b0 to your computer and use it in GitHub Desktop.
gitコマンド例
## リポジトリをローカルにコピー(オリジナルからforkした場合)
git clone https://github.com/yourname/c93-onestop-techbook.git .
git remote add upstream https://github.com/onestop-techbook/c93-onestop-techbook.git
## リポジトリをローカルにコピー(forkせずにオリジナルを直接使う場合)
git clone https://github.com/onestop-techbook/c93-onestop-techbook.git .
## トピックブランチを作る
git branch | grep '^\*' # 現在のブランチを確認
git fetch upstream # リポジトリをforkしてない場合は不要
git checkout master # masterブランチでなければmasterブランチに切り替え
git pull # リモートリポジトリの内容を反映
git checkout -b topic-xxx # トピックブランチを作成
## 変更をコミット
git add -p # 変更内容を確認しながら追加
git add newfile # ただしファイルの新規追加なら -p を使わない
git diff --cached # コミットする内容をプレビュー
git commit # コミット
## masterブランチを最新にしてから、トピックブランチをrebase
git branch | grep '^\*' # 現在のブランチが「topic-xxx」だとする
git fetch upstream # リポジトリをforkしてない場合は不要
git checkout master # masterブランチに切り替え
git pull # リモートリポジトリの内容を反映
git checkout - # 直前のブランチ(=topic-xxx)に切り替え
git rebase master # 最新のmasterから分岐したのと同じ状態にする
## pull requestを作る場合:トピックブランチをリモートブランチへpushする
git push -u origin topic-xxx # リモートリポジトリにpush
## pull requestを作らない場合:トピックブランチをmasterにマージしてpushする
git checkout master # masterブランチに切り替え
git merge --no-ff - # 直前のブランチ(=topic-xxx)をマージ
git push origin # リモートブランチに反映させる
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment