【Git】Git ~ git config あれこれ ~

■ はじめに

Git の設定により、色々トラブルが解決できるので、メモ。

なお、以下がとても参考になった。

https://qiita.com/hayamofu/items/d8103e789196bcd8b489

目次

【0】設定確認
 1)設定全体による確認
 2)設定個別での確認
【1】core.autocrlf : 改行コード変換ON/OFF
【2】core.ignorecase : 大文字・小文字を区別
【3】credential.helper : 認証情報
【4】user.name / user.email : ユーザ名・Email登録

【0】設定確認

1)設定全体による確認

# 設定一覧表示
git config -l

補足:.gitconfig

Windows だと「C:¥Users¥<UserName>」配下にある .gitconfig を
テキストエディタで開けば確認できる。

2)設定個別での確認

# 改行コード変換ON/OFF
$ git config core.autocrlf
true

【1】core.autocrlf : 改行コード変換ON/OFF

* 詳細は、以下の関連記事に記載。

Git ~ 改行コード自動変換 core.autocrlf ~
https://dk521123.hatenablog.com/entry/2021/08/17/171756

設定例

# core.autocrlf=false => コミット・チェックアウト時に改行コード変換をしない
git config --global core.autocrlf false

# or

# core.autocrlf=input => コミット時にのみ CRLF -> LF に変換
git config --global core.autocrlf input

# core.autocrlf=input の詳細は以下のサイトを参照。

https://qiita.com/shuhei/items/2da839de8803cb335f86

【2】core.ignorecase : 大文字・小文字を区別

設定例

# core.ignorecase=false => ファイルの大文字・小文字を区別する
git config --global core.ignorecase false

【3】credential.helper : 認証情報

* 認証を省略できる。
* 以下のサイトがまとまっている

https://chaingng.github.io/post/git_save_pw/
https://blog.codebase.co.jp/save-git-credential

設定例

# 保存モード「store」
# 認証情報をテキストファイルに保存する
# 永続的な保存が可能だが、平文でパスワードが保存される
git config --global credential.helper store --file

# リセット
git config --global --unset credential.helper

【4】user.name / user.email : ユーザ名・Email登録

git config --global user.name <your_user_name>
git config --global user.email <your_email_address>

元ネタ

* VS Code を通して Git でコミットしようとしたら、
 エラー「Make sure you configure your ‘user.name’ and ‘user.email’ in git.」
 が表示された対策として、使用した。
 => 詳細は、以下のサイトを参照のこと。

https://qiita.com/s_iida/items/bc3f68490d6c67c5b9ea

関連記事

Git ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2018/06/29/104028
Git ~ 基本編 / あれこれ ~
https://dk521123.hatenablog.com/entry/2018/07/01/005431
Git ~ 改行コード自動変換 core.autocrlf ~
https://dk521123.hatenablog.com/entry/2021/08/17/171756
PC が新しくなった際のGit/Githubの設定
https://dk521123.hatenablog.com/entry/2024/01/06/000000
Github ~ アクセストークン ~
https://dk521123.hatenablog.com/entry/2022/01/19/113903