Last active
October 14, 2022 14:24
-
-
Save code-yeongyu/e92f148ae34b94884993e6c29cae93fd to your computer and use it in GitHub Desktop.
Gitconfig setup with so many aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[difftool "sourcetree"] | |
cmd = opendiff \"$LOCAL\" \"$REMOTE\" | |
path = | |
[mergetool "sourcetree"] | |
cmd = /Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\" | |
trustExitCode = true | |
[filter "lfs"] | |
clean = git-lfs clean -- %f | |
smudge = git-lfs smudge -- %f | |
process = git-lfs filter-process | |
required = true | |
[alias] | |
alias-basic = "!#----------------------------------------------------------;\n\ | |
git alias | head -7" | |
ci = commit | |
co = checkout | |
sw = switch | |
re = restore | |
s = status -s | |
assume = update-index --assume-unchanged | |
assumed = "!git ls-files -v | grep ^h | cut -c 3-" | |
unassume = update-index --no-assume-unchanged | |
br-cl = "!# Clear merged branches.;\n\ | |
git branch --merged \ | |
| grep -v '*' \ | |
| grep -v master\ | |
| grep -v main\ | |
| grep -v develop\ | |
| xargs -n 1\ | |
git branch -d; echo 'Branch Cleared.'" | |
alias-log = "!#----------------------------------------------------------;\n\ | |
git alias | egrep 'log|commit-'" | |
commit-select = "!# Select a commit hash from log graph.;\n\ | |
git l \ | |
| fzf -m --ansi --layout=reverse --preview=\"echo {} | sed 's/^[*| ]*//g' | cut -d' ' -f1 | xargs git show --color=always \" \ | |
| sed 's/^[*| ]*//g' | cut -d' ' -f1" | |
c-s = "!git commit-select" | |
commit-copy = "!# Select & copy a commit hash from log graph.;\n\ | |
git commit-select | pbcopy && echo Copied : `pbpaste`;" | |
c-c = "!git commit-copy" | |
l = "log \ | |
--color --graph --decorate \ | |
--date=format:'%Y-%m-%d' \ | |
--abbrev-commit \ | |
--pretty=format:'%C(red)%h%C(auto)%d %s %C(green)(%cr)%C(bold blue) %an'" | |
ld = "log \ | |
--color --graph --decorate \ | |
--date=format:'%Y-%m-%d %H:%M:%S' \ | |
--abbrev-commit \ | |
--pretty=format:'%C(red)%h%C(auto)%d %s %C(green)(%ad)%C(bold blue) %an'" | |
ll = "log \ | |
--color --graph --decorate \ | |
--date=format:'%Y-%m-%d' \ | |
--abbrev-commit \ | |
--pretty=format:'%C(red)%H%C(auto)%d %s %C(green)(%cr)%C(bold blue) %an'" | |
lld = "log \ | |
--color --graph --decorate \ | |
--date=format:'%Y-%m-%d %H:%M:%S' \ | |
--abbrev-commit \ | |
--pretty=format:'%C(red)%H%C(auto)%d %s %C(green)(%ad)%C(bold blue) %an'" | |
lh = "!# Show log graph | head \n\ | |
f() { \ | |
if [ $# = 0 ]; then \ | |
git l -25; \ | |
else \ | |
git l -$1; \ | |
fi; \ | |
echo ''; \ | |
}; f" | |
ranking = "!# List commit counts of contributors;\n\ | |
git shortlog -sn" | |
alias-branch = "!#----------------------------------------------------------;\n\ | |
git alias | egrep '[bB]ranch'" | |
b0 = "!# Print current branch.;\n\ | |
git branch | awk '/^\\*/{print $2}'" | |
back = "!# Back up current branch.;\n\ | |
echo created new branch: backup-`git b0`;\ | |
git branch backup-`git b0`" | |
bb = "!# Branch tools. Type 'git bb help'.;\n\ | |
f() { \n\ | |
if [ $# = 0 ]; then \ | |
git branch-select | xargs git checkout; \ | |
elif [ $1 = 'help' ]; then \ | |
echo 'git bb : Select and checkout branch'; \ | |
echo 'git bb c, clean : Clean all merged branches'; \ | |
echo 'git bb d, D : Delete seleted branches(D: force)'; \ | |
echo 'git bb l, list : List branches excluding the current branch'; \ | |
echo 'git bb m, merged : List merged branches excluding the current and master branches'; \ | |
elif [ $1 = 'd' -o $1 = 'D' ]; then \ | |
git branch -$1 $(git bb list | fzf -m | awk '{print $2}'); \ | |
elif [ $1 = 'clean' -o $1 = 'c' ]; then \ | |
git branch-clean; \ | |
elif [ $1 = 'list' -o $1 = 'l' ]; then \ | |
git branch-list; \ | |
elif [ $1 = 'merged' -o $1 = 'm' ]; then \ | |
git branch-merged; \ | |
elif [ $1 = 'select' -o $1 = 's' ]; then \ | |
git branch-select; \ | |
else \ | |
git bb help; \ | |
fi; \ | |
}; f" | |
branch-clean = "!# Search and delete merged branches.;\n\ | |
curr_hash=`git show -s | head -1 | cut -d ' ' -f2`; \ | |
for branch in `find .git/refs -type f | fzf --ansi -m --preview=\"cat {} | xargs git l\"` ; do \ | |
hash=`cat $branch`; \ | |
if [ $hash = $curr_hash ]; then \ | |
continue; \ | |
fi; \ | |
git ll | egrep $hash -C 1; \ | |
read -p \"Delete $branch? [y|n] \" -r; \ | |
REPLY=${REPLY:-"n"}; \ | |
if [ $REPLY = \"y\" ]; then \ | |
rm $branch; \ | |
echo \"\\033[32m$branch \\033[0mhas been\\033[31m deleted\\033[0m.\n\"; \ | |
fi; \ | |
done" | |
b-c = "!git branch-clean" | |
branch-list = "!# List the branches.;\n\ | |
git for-each-ref --sort=-committerdate refs/heads --format='%(HEAD) %(refname:strip=2) | %(committerdate:relative) | %(authorname)' \ | |
| column -ts'|' \ | |
| sed 's/^ /./'" | |
b-l = "!git branch-list" | |
branch-list-all = "!# List all branches.;\n\ | |
for branch in `git branch -r --merged | grep -v HEAD`; do echo `git show --format=\"%ci ; %cr ; %an ;\" $branch | head -n 1` $branch; done | sort -r | column -ts';'" | |
b-la = "!git branch-list-all" | |
branch-select = "!# Select a branch.;\n\ | |
f() { \ | |
_height=$(stty size | awk '{print $1}');\ | |
git branch-list | fzf --preview \"git l {2} | head -n $_height\" | awk '{print $2}'; \ | |
}; f" | |
b-s = "!git branch-select" | |
ch = "!# Branch tools. Same with bb.;\n\ | |
git bb $1" | |
sync = "!# Sync with a branch with the same name in the remote repo.;\n\ | |
remote=$( \ | |
{ \ | |
git remote -v | egrep '^(origin|upstream)\\s'; \ | |
git remote -v | egrep -v '^(origin|upstream)\\s' | sort; \ | |
} \ | |
| awk '{print $1, $2}' | uniq \ | |
| column -t \ | |
| fzf | awk '{print $1}' \ | |
); \ | |
if ! [ -z $remote ]; then \ | |
git fetch $remote && git reset --hard $remote/`git b0`; \ | |
fi" | |
update = "!# Synchronize the contents of local files with the repository;\n\ | |
remote=$( \ | |
{ \ | |
git remote -v | egrep '^(origin|upstream)\\s'; \ | |
git remote -v | egrep -v '^(origin|upstream)\\s' | sort; \ | |
} \ | |
| awk '{print $1, $2}' | uniq \ | |
| column -t \ | |
| fzf | awk '{print $1}' \ | |
); \ | |
git stash; git pull --rebase $remote `git b0`; git stash pop;" | |
alias-stage = "!#----------------------------------------------------------;\n\ | |
git alias | egrep '(add|diff|stage)' -i" | |
a = "!# Select files and Add them.;\n\ | |
git diff-select | xargs git add" | |
a-c = "!# Add, Commit.;\n\ | |
git a; git commit" | |
diff-info = "!# Print diff report.;\n\ | |
fileA=/tmp/git-s-$(uuidgen); \ | |
fileB=/tmp/git-diff-$(uuidgen); \ | |
git s | awk '{print $2,$1}' > $fileA; \ | |
git diff --numstat | awk '{print $3,$1,$2}' > $fileB; \ | |
join -t' ' -a 1 $fileA $fileB | awk '{print $2, \"(+\"$3 \",-\"$4\")\", $1}' | sed 's/(+,-)/./; s/^\\([^?]\\) *\\./\\1 STAGED/' | column -t -s' ' ; \ | |
rm -f $fileA $fileB; \ | |
" | |
diff-select = "!# Select changed files to add them.;\n\ | |
f() { \ | |
git diff-info \ | |
| egrep -v '[^?] *STAGED ' \ | |
| fzf -m --header \"$(git diff --shortstat)\" --preview \ | |
\"if [[ {1} == '??' ]]; then bat {3}; else git diff --color=always {3}; fi\" \ | |
| awk '{print $3}'; \ | |
}; f" | |
diff-unselect = "!# Select staged files to unstage them.;\n\ | |
f() { \ | |
git diff-info \ | |
| egrep '[^?] *STAGED ' \ | |
| fzf -m --header \"$(git diff --shortstat)\" --preview \ | |
\"if [[ {1} == '??' ]]; then pygmentize {3}; else git diff --color=always --cached {3}; fi\" \ | |
| awk '{print $3}'; \ | |
}; f" | |
unstage = "!# Select staged files and Unstage them.;\n\ | |
git diff-unselect | xargs git reset HEAD" | |
alias-stash = "!#----------------------------------------------------------;\n\ | |
git alias | grep stash" | |
stash-apply = "!# Select a stash item and Apply it.;\n\ | |
git stash-op apply" | |
s-a = "!git stash-apply" | |
stash-drop= "!# Select the stash items and Drop them.;\n\ | |
for sid in $(git stash-select -m) ; do \ | |
git stash drop $sid; \ | |
done;" | |
s-d = "!git stash-drop" | |
stash-list = "!# List stash items.;\n\ | |
git stash list --pretty=format:\"%C(red)%gd%C(reset) %C(green)(%cr) %C(reset)%s\"" | |
s-l = "!git stash-list" | |
stash-pop= "!# Select a stash item and Pop it.;\n\ | |
git stash-op pop" | |
s-p = "!git stash-pop" | |
stash-save = "!# Save changes into the stash stack.;\n \ | |
git diff-info; \ | |
read -p \"save message: \" msg; \ | |
git stash save \"$msg\"" | |
s-s = "!git stash-save" | |
stash-select = "!# Select stash item(s).;\n\ | |
f() { \ | |
git stash-list \ | |
| fzf --ansi $1 --preview \"git stash show -p {1} --color=always\" \ | |
| cut -d' ' -f1; \ | |
}; f" | |
stash-op = "!#A private stash tool.;\nf() { git stash-select | xargs git stash $1; }; f" | |
tag-refresh = "!# Re reference tag.;\n \ | |
f() { \ | |
_height=$(stty size | awk '{print $1}');\ | |
tag_name=`git tag | fzf --preview=\"git l {1} | head -n $_height\" `; \ | |
echo $tag_name; \ | |
git tag -d $tag_name; \ | |
git tag $tag_name; \ | |
}; f" | |
alias-alias = "!#----------------------------------------------------------;\n\ | |
git alias | grep alias" | |
alias = "!# Prints all aliases.;\n\ | |
git config --list | egrep '^alias.+' | sed -e 's/^alias\\.//' | sed -e 's/^[^=]*=/\\'$'\\033[31m&\\033[(B\\033[m/' | column -t -s'=' | sed 's/!#* *//; s/;$//' | cut -c1-85" | |
alias-doctor = "!# Check the dependency tools.;\n\ | |
f() { \ | |
if [ $(which pygmentize | wc -l) -lt 1 ]; then \ | |
echo 'Not found : Pygments(pygmentize)'; \ | |
echo ' see : http://pygments.org/'; \ | |
echo ' install : pip3 install Pygments'; \ | |
echo '';\ | |
fi; \ | |
if [ $(which fzf | wc -l) -lt 1 ]; then \ | |
echo 'Not found : fzf'; \ | |
echo ' see : https://github.com/junegunn/fzf#installation'; \ | |
echo ' install(Mac) : brew install fzf'; \ | |
echo ' install(git) : git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf'; \ | |
echo ' ~/.fzf/install'; \ | |
echo '';\ | |
fi; \ | |
}; f" | |
[init] | |
defaultBranch = master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment