# 基本的な設定
## 自分の情報
git config --global user.name "User Name"
git config --global user.email "user.name@example.com"
## エイリアス
git config --global alias.co "checkout"
git config --global alias.b "branch"
git config --global alias.bd "branch -d"
git config --global alias.f "fetch -p"
git config --global alias.s "status"
git config --global alias.log1 "log --oneline --graph"
git config --global alias.log2 "log --graph --date-order -C -M --pretty=format:'%C(bold blue)%h%C(reset) %C(green)%ad%C(reset) %s %C(green)[%an]%C(reset) %C(yellow)%d%C(reset)' --date=format:'%Y-%m-%d %H:%M'"
git config --global alias.log3 "log2 --all"
git config --global alias.reset-commit "reset --soft HEAD^"
# ローカルブランチでマージ済みのものを削除
git config --global alias.localprune '!f() { git branch --merged | grep -v \* | xargs git branch -d; }; f'
# 改行コードの自動変換をOFF
git config --global core.autocrlf false
# push したときに自分のいるブランチを自動認識
git config --global push.default current
# config の内容を確認(grep の引数を渡せる)
git config --global alias.configrep '!f() { git config --show-origin -l | grep "$@"; }; f'
# commit の editor デフォルトを vi に(WSL2などで)
git config --global core.editor "vi"
# https で clone している場合でも自動的に ssh として remote 登録するように
git config --global url.git@github.com:.insteadOf https://github.com/
# ssh で git に繋ぐ際に訳(セキュリティ理由など)あって https で繋ぐ必要がある場合
vi ~/.ssh/config
# 末尾に下記追加
# ------------
Host github.com
Hostname ssh.github.com
Port 443
User git
# ------------
# WSL2 で gitbash のようなプロンプトに
curl -o ~/.git-prompt.sh https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
# プロンプトにブランチ名表示するように
vi ~/.bashrc
# 末尾に下記追加
# ------------
source ~/.git-prompt.sh
GIT_PS1_SHOWCOLORHINTS=true
PROMPT_COMMAND="__git_ps1 '\[\033[01;34m\]\w\[\033[00m\]' ' \\\$ '"
# ------------
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme