.gitconfig
早速ですが、gitconfigです。
[user]
name = ohnuma
email = <mail>
signingkey = "~/.ssh/id_ed25519.pub"
[http]
postBuffer = 500M
maxRequestBuffer = 100M
[cure]
compression = 0
[gpg]
format = ssh
[gpg "ssh"]
allowedSignersFile = /Users/user/.ssh/allowed_signers
[commit]
gpgsign = true
[alias]
graph = log --graph --date=short --decorate=short --pretty=format:'%Cgreen%h %Creset%cd %Cblue%cn %Cred%d %Creset%s'
gr = log --graph --date=short --decorate=short --pretty=format:'%Cgreen%h %Creset%cd %Cblue%cn %Cred%d %Creset%s'
pushff = push --force-with-lease --force-if-includes
st = status
ss = status -s
ad = add
cm = commit
stt = status -uno
df = diff --color-words
dc = diff --cached
dp = diff --no-prefix
d1 = diff HEAD~
d2 = diff HEAD~~
d3 = diff HEAD~~~
d4 = diff HEAD~~~~
co = checkout
cob = checkout -b
br = branch
f = fetch
rb = rebase
rba = rebase --abort
rbc = rebase --continue
amd = commit --amend --no-edit
res1 = reset HEAD^
wip = !git add . && git commit -m 'wip'
commitwith = "!sh -c 'git add . && git commit -m \"$1\"' -"
[init]
defaultBranch = main
[includeIf "gitdir:~/dev/other/"]
path = ~/.gitconfig_other
お気持ち
gpgについて
以下らへんで署名付きコミットの設定を行なっています。
gpgではなく、ssh鍵で署名できるので、そちらで対応しています。
[gpg]
format = ssh
[gpg "ssh"]
allowedSignersFile = /Users/user/.ssh/allowed_signers
[commit]
gpgsign = true
ここら辺の設定については以下の記事を書いていますのでよければ読んでください。
includeIfについて
githubアカウントを複数使う場合でsshの鍵など、違うものを設定したい場合など、
環境ごとで.gitconfigの設定をオーバーライドしたい時にIncludeIfが便利です。
[includeIf "gitdir:~/dev/other/"]
path = ~/.gitconfig_other
詳しくは以下の記事で書いていますのでよければお読みください。
aliasについて
たくさん設定していますが、よく使っているのは、
- pushff (force push)
- d1~d4 (HEADからのdiff)
- co, cob (checkout)
- br (branch)
- f (fetch)
- rb (rebase)
- amd (--amend --no-edit)
- res1 (reset)
- wip (wipというコミットメッセージでcommit)
- graph (commit log treeをいい感じに出す)
くらいです。
シェルでのエイリアス
シェルはfishをつかっていますがよく使う status と graph についてはシェル側のエイリアスで設定してしまっています。
alias gs "git status"
alias ggr "git graph"
そのため上記で設定してはありますが、 git st や git gr などを叩くことはほとんどありません。
Lazygitについて
git操作をGUIで行えるLazyGitも便利です。
特にgit add -pが格段にやりやすくなります。
普段のadd, commitはlazygitを使って操作してしまうことが多いです。
終わりに
もっと良いgitconfigをお持ちの方は教えてください。