5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

「脱Git初心者」一歩差が出るgitconfigの設定

5
Last updated at Posted at 2024-04-20

有用なgit config

はじめに

So You Think You Know Git 2024をみてgitconfigの設定をいじることでかなり生産性が上げられそうだなと感じたので紹介されていたものを自分なりに取り入れてみたので防備録代わりに投稿します。


よく使う基本の設定

この辺はみんなやっていると思うので詳細は割愛。

username="sigma"
usermail="example@gmail.com"
git config --global user.name "${username}"
git config --global user.email "${uesremail}"

git config --global color.ui auto
git config --global core.editor vim # コミットメッセージの修正に使うエディタをvimにする
git config --global core.ignorecase false # ファイル名の大文字小文字の変化を検知できるようにする。

stash実行時にstash --allが実行されるようになる

  • stash --allはすべての変更を一時的なスタッシュに保存する。
git config --global alias.staash 'stash --all'

git bbでカスタムスクリプトを実行させる

  1. better-branch.shをコピペして~/initialsetting/配下に保存
  2. config追加。
git config --global alias.bb '!/home/tomita/initialsetting/better-branch.sh'

解決したことのあるコンフリクトを記録して自動で解消されるようになる。

git config --global rerere.enabled true

git branchの結果を複数行にする

  • git branch実行時にgit branch --columnが実行されるようにする。
git config --global column.ui auto

ツリーの生成を早くする。

git config --global fetch.writeCommitGraph true
git log --graph --oneline

git maintenanceを使う

  • gitは到達不可能オブジェクトを削除する等のガーベジコレクションを行っているがこれはコマンドを実行するタイミングである。
  • 大規模プロジェクトでは時間がとられる可能性があるので定期的にgcするようにする。

git maintenance

git maintenance start # 特定のリポジトリに対するメンテナンスを実行する。

rebase時に自動で編集中のファイルをstashする。

  • rebase時に自動でstashしてくれる。
git config --global rebase.autoStash true

自動でfixupされるようにする

git config --global rebase.autosquash true
git commit -m "test" --fixup=HEAD # fixup!がついたコミットを生成
git rebase -i HEAD~2 # fixupがついたコミットを自動でfixupにする

[!WARNING]
git rebaseするまではfixupのタグがついたコミットになるだけなのでrebaseすること。


push --force-with-leaseのエイリアス

git config --global alias.pushf 'push --force-with-lease'
# 使い方
git pushf -u origin main

ファイルシステムのモニタを早くする(大規模プロジェクトで役に立つシリーズ)

  • gitはファイルシステムから直接未追跡ファイルの情報を問い合わせるため,大規模プロジェクトではgit statusするだけで時間がかかることがある。
  • ファイルの更新をローカルでキャッシュしておくことで動作を早くできる
git config core.untrackedCache true

# ファイルシステムの監視を利用してファイルの変更をリアルタイム検出できる。大規模プロジェクトで役立つ。
git config core.fsmonitor true

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?