-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathgit.sh
More file actions
70 lines (61 loc) · 2.07 KB
/
git.sh
File metadata and controls
70 lines (61 loc) · 2.07 KB
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
# Wrap 'git' with 'hub' - if we have hub installed.
if [ -x "$(command -v hub)" ]; then
eval "$(hub alias -s)"
fi
# Basic alises based on the 'git' OMZ plugin.
# For reference, see:
# https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/git/git.plugin.zsh
git_current_branch() {
git branch --show-current
}
# Check if main exists and use instead of master
git_main_branch() {
command git rev-parse --git-dir &>/dev/null || return
local ref
for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,stable,master}; do
if command git show-ref -q --verify $ref; then
echo ${ref:t}
return 0
fi
done
# If no main branch was found, fall back to master but return error
echo master
return 1
}
# Basic alises based on the 'git' OMZ plugin.
# https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/git/git.plugin.zsh
alias ga='git add'
alias gb='git branch'
alias gd='git diff'
alias gf='git fetch'
alias gco='git checkout'
alias gcb='git checkout -b'
alias gc='git commit --verbose'
alias gst='git status'
alias gsm='git switch main'
alias gsml='git switch main && git pull'
alias gcm='git checkout main'
alias gl='git pull'
# Push to origin.
gpo() {
git push --set-upstream origin "$(git_current_branch)"
}
# My own personal git functions or shorthands.
# Clone from GitHub.
ghclone() {
git clone git@github.com:$1
}
# Release-As - useful for Release-Please
release_as() {
git commit --allow-empty -m "chore: release $1" -m "Release-As: $1"
}
# Not really a command, but a much nicer version of git branch.
# Source: https://stackoverflow.com/questions/2514172/listing-each-branch-and-its-lastevisions-date-in-git
alias gbranch='for k in `git branch -l | \
perl -pe '\''s/^..(.*?)( ->.*)?$/\1/'\''`; \
do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k -- | \
head -n 1`\\t$k; done | sort -r'
alias gbranchr='for k in `git branch -r | \
perl -pe '\''s/^..(.*?)( ->.*)?$/\1/'\''`; \
do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k -- | \
head -n 1`\\t$k; done | sort -r'