git,git-flowのインストールと設定のまとめ

入社以来ずっとSVN使ってきたけど、gitの環境に変わったのでgitの導入手順とか設定をまとめておく。

gitのインストールと設定

$ sudo yum install git
$ apt-get install git


ユーザ設定


基本的な設定

$ git config --global user.name "hoge"
$ git config --global user.email "hoge@example.com"

色やエイリアスの設定

$ git config --global color.ui auto
$ git config --global alias.co checkout
$ git config --global alias.ci commit
$ git config --global alias.st status
$ git config --global alias.br branch
$ git config --global alias.hist 'log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short'

自分用のgitignore設定

  • .swpとか除外しとく
$ git config --global core.excludesfile ~/.gitignore

git-flowのインストール

$ wget --no-check-certificate -q -O - https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh | sudo bash

git-flowは、ブランチモデルを補助する機能を提供してくれる。
git-flowの使い方はgit flow でのチーム開発ワークショップ資料 - Yamashiro0217の日記を参考にすると分かりやすい。

コマンド補完


git

gitインストール時にgit-completion.bashという設定ファイルも落としてきているので、それを読み込ませれば補完が効くようになる。

  • ~/.bashrcに以下の様にgit-completion.bashを読み込ませる記述を追記
source gitインストールディレクトリ/contrib/completion/git-completion.bash

git-flow

git-flow用のcompletion.bashは、git-flowには用意されていないので別に取得する。

$ wget -O /etc/bash_completion.d/git-flow-completion.bash https://raw.github.com/bobthecow/git-flow-completion/master/git-flow-completion.bash

gitと同じように、~/.bashrcにgit-flow-completion.bashを読み込ませる記述を追記

source 任意の保存ディレクトリ/git-flow-completion.bash

ターミナルに現在のbranchを表示する


~/.bashrcに以下を追記

PS1="[\u:\W\$(__git_ps1)]\$ " 

最後に忘れずに、.bashrcを読み込んで設定を反映させる。

$ source ~/.bashrc


これで当面やってみる。
なにかオススメの設定とかあれば、教えてください!


参考

見えないチカラ: A successful Git branching model を翻訳しました

git flow でのチーム開発ワークショップ資料 - Yamashiro0217の日記

Gitコマンドをタブキーで補完できるようにする | mawatari.jp

git-flowのインストールとタブキーによるコマンド補完 | mawatari.jp