普段、gitはコマンドラインで使っています。
で、よく使うものがオプション込みで使っている場合、打つのが面倒くさいんですよね。
ってことで、自分用に設定方法とエイリアスをまとめてみました。
設定方法
エイリアスのスコープは、3種類
- システム
- ユーザ
- リポジトリ
詳しくは、こちらを見てください。
ここでは、設定するためのコマンドだけ書いておきます。
git config
設定内容
sudo git config --system alias.st "status" && \
sudo git config --system alias.cm "commit -m" && \
sudo git config --system alias.prbr '!prbr() { git checkout $1 > /dev/null && git pull -p && git branch --color -a; }; prbr' && \
sudo git config --system alias.master '!master() { git checkout master > /dev/null && git pull -p && git branch --color -a; }; master' && \
sudo git config --system alias.mgcm "merge --no-ff --no-edit" && \
sudo git config --system alias.ba "branch --color -a" && \
sudo git config --system alias.del "branch -D" && \
sudo git config --system alias.pdel "push --delete origin" && \
sudo git config --system alias.graph "log --graph --date=short --pretty='format:%C(yellow)%h %C(cyan)%ad %C(green)%an%Creset%x09%s %C(red)%d%Creset'" && \
sudo git config --system alias.gp "log --graph --date=short --pretty='format:%C(yellow)%h %C(cyan)%ad %C(green)%an%Creset%x09%s %C(red)%d%Creset'" && \
sudo git config --system alias.gpa "log --graph --all --date=short --pretty='format:%C(yellow)%h %C(cyan)%ad %C(green)%an%Creset%x09%s %C(red)%d%Creset'" && \
sudo git config --system alias.lfm "log --date=short --pretty='format:%C(yellow)%h %C(cyan)%ad %C(green)%an%Creset%x09%s %C(red)%d%Creset'" && \
sudo git config --system alias.lms "log master origin/master --date=short --pretty='format:%C(yellow)%h %C(cyan)%ad %C(green)%an%Creset%x09%s %C(red)%d%Creset'" && \
sudo git config --system alias.back "reset HEAD^ --soft" && \
sudo git config --system alias.unstage "reset HEAD" && \
sudo git config --system alias.work '!gws() { git checkout master > /dev/null && git pull -p && git checkout -b $1 > /dev/null; }; gws' && \
sudo git config --system alias.pcb '!pcb() { git checkout -b $1 && git commit -a -m $2 && git push -u origin $1; }; pcb' && \
sudo git config --system alias.ignore '!gi() { curl -L -s https://www.gitignore.io/api/$@ >> .gitignore;}; gi' && \
sudo git config --system alias.ignore-p '!gi() { curl -L -s https://www.gitignore.io/api/$@ ;}; gi' && \
sudo git config --system alias.ignore-g '!gi() { curl -L -s https://www.gitignore.io/api/$@ >> ~/.gitignore_global;}; gi'
sudo git config --system alias.subup '!subup() { git submodule init && git submodule update && cd $1 && git pull && cd ../; }; subup'
設定内容の確認方法
# システムの設定
git config --system -l
cat /etc/gitconfig
# ユーザの設定
git config --global -l
cat ~/.gitconfig
# リポジトリの設定
git config --local -l
cat .git/config
グローバルなgitignoreの設定
エイリアスではないけれど、必要なため記述(ここで設定したエイリアスを利用すると必要になるものがある)。
ユーザごとの設定とするため、--global
で設定している。
git config --global core.excludesfile ~/.gitignore_global
参考文献
gitで便利なエイリアス達
git log よく使うオプションまとめ
変更履歴
ここにあるものは全て、この記事の本文中に存在しています。
2018/07/14
### 以下はshell上で実行 ###
# gitのエイリアスの設定内容
sudo git config --system alias.del "branch -D"
### 以下は ~/.bashrc に追加 ###
# Gitでの開発用にコマンドのエイリアスを貼る
function gws() { git checkout master > /dev/null && git pull -p && git checkout -b $1 > /dev/null; }
alias gws=gws
2018/07/20
# gitのエイリアスの設定追加
sudo git config --system alias.cm "commit -m"
2018/07/27
# gitのエイリアスの設定追加
sudo git config --system alias.work '!gws() { git checkout master > /dev/null && git pull -p && git checkout -b $1 > /dev/null; }; gws' && \
sudo git config --system alias.ignore '!gi() { curl -L -s https://www.gitignore.io/api/$@ >> .gitignore;}; gi' && \
sudo git config --system alias.ignore-p '!gi() { curl -L -s https://www.gitignore.io/api/$@ ;}; gi' && \
sudo git config --system alias.ignore-g '!gi() { curl -L -s https://www.gitignore.io/api/$@ >> ~/.gitignore_global;}; gi'
# グローバルなgitignoreの設定
git config --global core.excludesfile ~/.gitignore_global
### 以下は ~/.bashrc 内の操作 ###
# 以前作成したエイリアスの削除(以下の内容を削除)
function gws() { git checkout master > /dev/null && git pull -p && git checkout -b $1 > /dev/null; }
alias gws=gws
2018/08/06
# gitのエイリアスの設定追加&変更
## 親ブランチの更新
sudo git config --system alias.prbr '!prbr() { git checkout $1 > /dev/null && git pull -p && git branch --color -a; }; prbr' && \
sudo git config --system alias.master '!master() { git checkout master > /dev/null && git pull -p && git branch --color -a; }; master'
2018/08/19
# gitのエイリアスの設定追加
## マージに絶対にコミットを付ける
sudo git config --system alias.mgcm "merge --no-ff"
2018/09/01
# gitのエイリアスの設定変更
## マージ時にコミット編集画面を開かない
sudo git config --system alias.mgcm "merge --no-ff --no-edit"
2018/09/28
# gitのエイリアスの設定変更
## リモートブランチを削除する
sudo git config --system alias.pdel "push --delete origin"
## 新しくブランチを作成・初期コミット・リモートにプッシュする
sudo git config --system alias.pcb '!pcb() { git checkout -b $1 && git commit -a -m $2 && git push -u origin $1; }; pcb'
2019/09/03
# gitのエイリアスの設定追加
特定のサブモジュールを更新する
sudo git config --system alias.subup '!subup() { git submodule init && git submodule update && cd $1 && git pull && cd ../; }; subup'