とりあえず.gitconfigをいじっとけという話。

これすんごい良いです。
まだChapter 06までしか読んでないんですけども。
すんごいよさそうです。

プロフェッショナルプログラミングだからプロプロって呼ぶんかと思ったら、
pypro(ぱいぷろ)って呼ぶらしいですね。気に食わないからプロプロって呼びますね。

ということで、今回は、プロプロにも書いてあった内容(Chapter 03)gitconfig について。

まずは以下を打ちましょう。

$ git config --list

ハイ、何が出てきますか。 何も出てこないあなたは人生損してます。

定番

git config --global user.name {ユーザー名}
git config --global user.email {メールアドレス}

これを設定していないとpushの度に入力が必要になっちゃいます。設定しときましょう。

コマンドのしくみ

git config --global user.name "nkimoto"

コマンドのしくみを解体していきましょう。
--globalで設定のスコープ(対象とする範囲)を。
user.name "nkimoto" で設定するkeyとそのvalueを指定しています。

これを打つと、~/.gitconfigに以下のように追記される仕組みになってます。

[user]
        name = nkimoto

めちゃシンプルです。

git configのスコープ

gitでは、対象とする範囲ごとにファイルを作成できるのです。

system, global, local の3種類。それぞれ、

  • system
    システム全体に反映。ファイルは/etc/gitconfigに作られる。
  • global
    ユーザ全体 。ファイルは~/.gitconfigに作られる。
  • local
    対象リポジトリのみ。ファイルは./.git/configに作られる。

同じkeyが複数のファイルで設定されている場合、
system > global > local の順に優先されます。
実体はただのテキストファイルなので、手動でいじることも可能です。

kimotonのすゝめ。

おすすめの設定を張っておきます。ぜひぜひ使ってやってください。

## ユーザー認証
git config --global user.name {ユーザー名}
git config --global user.email {メールアドレス}

## 使用するエディターの設定
git config --global core.editor vim

## 使用するエディターの設定(コンフリクト時)
git config --global merge.tool vimdiff

## chmod でのpermission変更を無視
git config --global core.filemode false

## .gitignore_globalの利用
git config --global core.excludesfile  ~/.gitignore_global

## カラー出力の有効化
git config --global color.ui auto

## 以下、エイリアスの設定
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.up rebase
git config --global alias.ci commit

作られるファイル:~/.gitconfig

[core]
        filemode = false
        editor = vim
        excludefile = ~/.gitignore_global
[user]
        email = {メールアドレス}
        name = {ユーザー名}
[merge]
        tool = vimdiff
[alias]
        st = status
        co = checkout
        br = branch
        up = rebase
        ci = commit
[color]
        ui = auto

おまけ

エディタで編集

git config --global -eでエディタを開いて編集できちゃう。
--global--system--localで編集対象のファイルを指定できます。