Introduction
Describes how to set an alias for a Git command.
It all started when I happened to be using Git in my work and was curious about alias settings.
About Alias
This setting is used to omit commands used in Git.
Example
- Before Abbreviation
git status
- After Abbreviation
git s
Setup Procedure
Commands to set Alias settings
Perform Alias configuration for the following commands
git log --graph --all --color --pretty='%x09%h %s %Cred%d%Creset %C(green)- %ad%Creset c:%cn:%ce a:%an:%ae' --date=format:'%Y/%m/%d %H:%M:%S%z'
This command makes the git log easier to read.
Examples of use are as follows.
% git log --graph --all --color --pretty="%x09%h %s %Cred%d%Creset %C(green)- %ad%Creset c:%cn:%ce a:%an:%ae" --date=format:"%Y/%m/%d %H:%M:%S%z"
* 4c001c1 Update READMD.md (HEAD -> work, origin/work) - 2022/06/19 15:28:05+0900 c:masuwa:xxxxxxxxxxx@gmail.com a:masuwa:xxxxxxxxxxx@gmail.com
* 20ac8ba Initial commit (origin/main, origin/HEAD, main) - 2022/06/19 13:15:40+0900 c:GitHub:noreply@github.com a:masuwa9028:105219153+masuwa9028@users.noreply.github.com
%
Alias Setting
Setting File
Range to be reflected | Configuration file to be edited |
---|---|
Entire system | /etc/gitconfig |
User |
~/.gitconfig or ~/.config/git/config
|
Repository | Repository root directory/.git/config |
※This time, modify ~/.gitconfig
.
Setting
- Modify
~/.gitconfig
.
Add the following to ~/.gitconfig
.
[alias]
tree = log --graph --all --color --pretty='%x09%h %s %Cred%d%Creset %C(green)- %ad%Creset c:%cn:%ce a:%an:%ae' --date=format:'%Y/%m/%d %H:%M:%S%z'
- Check if the command is available.
Verify that the git tree command is working.
% git tree
* 4c001c1 Update READMD.md (HEAD -> work, origin/work) - 2022/06/19 15:28:05+0900 c:masuwa:xxxxxxxxxxx@gmail.com a:masuwa:xxxxxxxxxxx@gmail.com
* 20ac8ba Initial commit (origin/main, origin/HEAD, main) - 2022/06/19 13:15:40+0900 c:GitHub:noreply@github.com a:masuwa9028:105219153+masuwa9028@users.noreply.github.com
%
Reference
【git】aliasの設定方法
2.7 Git の基本 - Git エイリアス
ダブルクォートを含むコマンドをそのままaliasにすると失敗しがち
Top comments (0)