-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.zshrc_git_ext
81 lines (66 loc) · 2.62 KB
/
.zshrc_git_ext
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
# Git aliases
alias glog="git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --branches"
alias gaac="git add . && git commit -a --interactive"
alias gac="git add --patch && git commit --interactive"
alias gam="git commit --amend"
alias gpf="git push --force-with-lease"
alias gsw="git switch"
alias gswc="git switch --create"
alias gst="git status"
alias gpsu="git push --set-upstream origin \$(git branch --show-current)"
alias git_list_local_only_branches="git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '\$2 == \"[gone]\" {sub(\"refs/heads/\", \"\", \$1); print \$1}'"
function git_delete_branch_prompt() {
branch=$1
read -q "REPLY?Delete $branch? [y/N] "
echo ""
if [[ "$REPLY" = "y" ]]; then
git branch -D $branch
fi
}
alias git_prune_local_branches="git fetch -p && for branch in \$(git_list_local_only_branches); do git_delete_branch_prompt \$branch; done"
function gacp() { gac "$@" && git push }
alias gfetch="git fetch origin"
alias greb="git rebase"
alias grebc="git rebase --continue"
alias gbparent='git show-branch \
| sed -E "s/([\^~]+.*)*].*//" \
| grep "\*" \
| grep -v "$(git rev-parse --abbrev-ref HEAD)" \
| head -n1 \
| sed "s/^.*\[//"'
alias gsq="git reset --soft \$(git merge-base HEAD \$(gbparent)) && git commit"
alias gremreb="gfetch -p && gfetch \$(gbparent) && greb origin/\$(gbparent)"
alias gsqreb="gfetch -p && gfetch \$(gbparent) && gsq && greb origin/\$(gbparent)"
alias gresempty="git reset --soft \$(git log -1 --grep='.' --pretty=format:'%h')"
alias gsempty="gresempty && gsc"
alias gamempty="gresempty && gam"
# Open the Pull Request URL for your current directory's branch (base branch defaults to main)
alias giturl="git remote -v | awk '/fetch/{print \$2}' | sed -Ee 's#(git@|git://)#https://#' -e 's@com:@com/@' -e 's%\.git$%%' | awk '/github/'"
function gitprs() {
github_url=`giturl`;
prs_page=$github_url"/pulls"
open $prs_page
}
function openpr() {
target_branch="${1:-master}"
github_url=`giturl`;
branch_name=`git symbolic-ref HEAD | cut -d"/" -f 3,4`;
pr_url=$github_url"/compare/$1..."$branch_name;
open $pr_url;
}
function opengit() {
base_github_url=`giturl`;
branch_name=`git symbolic-ref HEAD | cut -d"/" -f 3,4`;
github_url=$base_github_url"/tree/"$branch_name;
open $github_url;
}
function glreb(){ gsw $1 && gl && gsw - && greb $1; }
# Run git push and then immediately open the Pull Request URL
function gpr() {
git push origin HEAD
if [ $? -eq 0 ]; then
openpr
else
echo 'failed to push commits and open a pull request.';
fi
}