ローカル作業でのgitリポジトリ管理とコーディング環境の話
gitを改めてちゃんと使おうという人がまわりで増えてきたのでメモとして貼っておく。
現状の設定はこんな感じ。1年くらい変わってなかった。
https://github.com/suzuken/dotfiles/blob/cbf8e7168c96029d535d69f981337d23aacfa51c/gitconfig
特にaliasまわりは普段つかっているのであげておく。
[alias] # http://oli.jp/2012/git-powerup/ # http://blog.blindgaenger.net/advanced_git_aliases.html alias = !git config --list | grep 'alias\\.' | sed 's/alias\\.\\([^=]*\\)=\\(.*\\)/\\1\\\t => \\2/' | sort b = branch -a br = browse-remote ci = commit co = checkout current-branch = rev-parse --abbrev-ref HEAD d = diff dc = diff --cached di = diff dic = diff --cached f = fetch --prune fs = !git f && git su ignore = !([ ! -e .gitignore ] && touch .gitignore) | echo $1 >> .gitignore info = remote show origin l = log --graph -n 20 --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(green)- %an, %cr%Creset' ll = log --stat --abbrev-commit ln = log --graph -n 20 --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(green)- %an, %cr%Creset' --name-status lp = log --oneline -n 20 -p ls = log --stat --abbrev-commit -n 1 # display previous log s = status --short --branch st = status su = submodule update delete-merged-branches = !git branch --merged | grep -v \\* | xargs -I % git branch -d % fetch-pulls = fetch origin +refs/pull/*:refs/remotes/pull/*
特によく使うのは delete-merged-branches
と fetch-pulls
。remoteでbranchがマージされてfetchしてきたときに既にmergeしてるものだけどlocalブランチから消す。これをやると現在mergeされていないブランチのみが残るので便利。 fetch-pulls
はcodeをレビューするときとかにつかっていて、これをつかうと対象プロジェクトのPull Requestをまとめてfetchできる。するとローカルでdiffもとりやすいし便利。
あとはマージにはvimdiffを使ってる。それと git clone
は ghq clone
motemen/ghq でつかっていて、全部GOPATHっぽく入るようになってる。これを peco
peco/peco で探すようにしているので、大分ローカルでのリポジトリの移動が楽になった。普段はvimでコーディングしているので mattn/ctrlp-ghq でプロジェクトを行ったり来たりしている。だいたい新しいtab開いて ctrlp-ghq
でcurrent directoryを移動して Dirvish
justinmk/vim-dirvish でそこのrootを開く、ということをしてることが多い。基本的に全部動作が軽いのを選ぶようにしてる。
気が付くとvimの話になってしまったので反省している。