-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitconfig
118 lines (115 loc) · 5.05 KB
/
.gitconfig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
[user]
name = "Chris Lee"
email = "[email protected]"
[core]
editor = vim
[pull]
rebase = true
[diff]
tool = difftastic
external = difft
[difftool]
prompt = false
[difftool "difftastic"]
cmd = difft "$LOCAL" "$REMOTE"
# Use a pager for large output, just like other git commands.
[pager]
difftool = true
[alias]
# `git dft` is less to type than `git difftool`.
dft = difftool
# diff against upstream main
dfm = diff origin/main
# Aliases taken from
# https://opensource.com/article/20/11/git-aliases
# Shows the status in a short fashion and shows the branch name.
st = "status -sb"
# Gets a list of the files added or updated.
# Filters out files that were deleted and the old file names if they were
# renamed.
stlist = !"git status --porcelain | sed '/^D /d' | sed '/ D /d' | sed 's/^...//' | sed 's/.*-> //'"
# Commits with a message.
cm = "commit -m"
cnv = "commit --no-verify"
# Commits with a message without verifying.
cmv = "commit --no-verify -m"
# Checks out a branch.
co = "checkout"
# Shows all of the previous commits in a compact way.
ll = "log --graph --pretty=oneline --abbrev-commit"
# Copies the SHA for the last commit. Useful for cherry picking when splitting branches.
l = !"git rev-parse --verify HEAD | pbcopy"
# Shows the last commit in detail.
last = "log -1 HEAD --stat"
# Just shortens the diff.
d = "diff"
# Shows the shortened summary of the diff. Example: git ds main
ds = "diff --stat"
# Opens vimdiff to see diffs side by side.
dv = "difftool -t vimdiff -y"
# Takes the current changes and amends them to the previous commit without renaming the commit.
amend = "commit --amend --no-edit"
amv = "commit --amend --no-edit --no-verify"
# Uncommits the most recent commit. Typically used in combination with `git tmp` to
# pause and restart work.
undo = "reset HEAD~1"
# Using this flag, git checks if the remote version of the branch is the same
# as the one you rebase, i.e. did someone push new commits when we were
# rebasing. The push is then rejected if the remotes branch is changed.
pf = "push --force-with-lease"
# Creates a new branch.
b = "checkout -b"
# Lists all branches that have my name in them.
bs = "branch -a --list \"chris*\""
# Pushes a local branch to origin. I typically use this after creating a local branch with `git b` and adding code
# that I'm ready to upload for others to see.
pu = !"git push --set-upstream origin $(git branch --show-current)"
# Amends the previous commit and allows for the commit message to be changed.
rename = "commit --amend"
se = ! "git rev-list --all | xargs git grep -F"
# Cleans up local git branches deleted on remote.
# https://www.erikschierboom.com/2020/02/17/cleaning-up-local-git-branches-deleted-on-a-remote/
gone = ! "git fetch -p && git for-each-ref --format '%(refname:short) %(upstream:track)' | awk '$2 == \"[gone]\" {print $1}' | xargs -r git branch -D"
# Adds all current changes into a commit called `tmp`. If the last commit is called `tmp`, this will amend
# the changes. Otherwise, this will create a new commit.
tmp = !"if [[ \"$(git log -1 --pretty=%B)\" = \"tmp\" ]]; then git add -A && git amend --no-verify; else git add -A && git cm \"tmp\" --no-verify; fi"
# A workaround since VS Code takes so long to load...
gofmt = !"for f in $(git stlist | grep '.*go'); do go fmt $f; done"
# Lists the history of commits that have modified a file.
# Usage: `git fhist <filename>`.
fhist = !"git log --follow -- "
a = "add -A"
# Merge main into current branch.
mg = !"git fetch origin main && git merge origin/main"
# Pull and get rid of branches
pl = !"git checkout main && git pull && git gone"
rbm = "rebase origin/main"
# https://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit
# Recent Branches
rb = !"r() { \
refbranch=$1; \
count=$2; \
lines=$(git for-each-ref refs/heads \
--sort=-committerdate \
--format='%(refname:short)|%(HEAD)%(color:yellow)%(refname:short)|%(color:bold green)%(committerdate:relative)|%(color:blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)' \
--color=always \
--count=${count:-100}); \
rows=$(echo \"$lines\" | while read line; do \
branch=$(echo \"$line\" | \
awk 'BEGIN { FS = \"|\" }; { print $1 }' | \
tr -d '*'); \
ahead=$(git rev-list --count \"${refbranch:-origin/main}..${branch}\"); \
behind=$(git rev-list --count \"${branch}..${refbranch:-origin/main}\"); \
colorline=$(echo \"$line\" | sed 's/^[^|]*|//'); \
echo \"$ahead|$behind|$colorline\" | awk -F'|' -vOFS='|' '{$5=substr($5,1,70)}1' ; \
done); \
rows=$(echo \"ahead|behind|branch|lastcommit|message|author|pr\" && echo \"$rows\"); \
echo \"$rows\" | while read line; do \
echo \"$line\"; \
done | column -ts'|'; \
}; r"
# Open the associated GitHub PR (for the current branch) in the web.
open = !"gh pr view --web"
repo = !"gh repo view --web"
code = !"code $(git diff main --name-only)"
snippet = "log origin/main --author='Chris Lee' --pretty=format:'%h - %an, %ar : %s'"