-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-shortcuts.bash
138 lines (110 loc) · 2.66 KB
/
git-shortcuts.bash
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
export CURRENT_BRANCH_NAME=""
export JIRA_TAG=""
export LOOP_STATUS_INTERVAL=60
# git - status
# Git status
gs() {
git status
}
# git - branch
# Git branch
gb() {
git branch
}
gsb() {
git status
git branch
}
# git - update rebase branch
# On the current branch, checkout out master and pull the latest changes. Then switch back to your branch and rebase on master.
gurb() {
update_main_branch
git rebase $GIT_SHORTCUTS_BRANCH
}
gumb() {
update_main_branch
git merge $GIT_SHORTCUTS_BRANCH
}
update_main_branch() {
get_current_branch_name
git checkout $GIT_SHORTCUTS_BRANCH
git pull
git checkout $CURRENT_BRANCH_NAME
}
# git - commit
# Commit current changes with a message
gc() {
get_current_branch_name
git commit -m "$1"
}
#git - tagged commit
# Commit with a JIRA tag pulled from the branch name
gtc() {
get_jira_tag
gc "$JIRA_TAG: $1"
}
# git - force push
# Force push commits
gfp() {
git push --force
}
# git - add all
# Add all staged files
ga() {
git add -A
}
# git - diff master
alias gdm="git diff origin/master"
# git - checkout master copy
alias gcm="git checkout -- $1"
# git - remove all branches (except master)
alias grab="git branch | grep -v "master" | xargs git branch -D"
# git - remove ticket branches
alias grtb="git branch | grep -v $1 | xargs git branch -D"
# git - open pull request
gopr() {
git pull-request -F ~/pr-message.md | pbcopy
}
# Add all changes and commit with message
gitready() {
ga
gtc "$1"
}
# Push branch to origin (just in case it already isn't linked with your local branch
# Pull the latest changes from master and rebase your branch against master
# Force push your branch to the origin
gitrdone() {
get_current_branch_name
git push --set-upstream origin $CURRENT_BRANCH_NAME
gurb
gfp
}
get_current_branch_name() {
# Get current branch name
branch_name="$(git symbolic-ref HEAD 2>/dev/null)" ||
branch_name="(unnamed branch)" # detached HEAD
branch_name=${branch_name##refs/heads/}
CURRENT_BRANCH_NAME=$branch_name
}
get_jira_tag() {
get_current_branch_name
JIRA_TAG=$( echo $CURRENT_BRANCH_NAME | cut -d_ -f1 )
}
# git - checkout pull request
# Checks out a pull request from the repo defined at $GIT_SHORTCUTS_REPO.
# The input for the function should be the PR number which is also the last piece of the url.
# Ex "https://github.com/pelotoncycle/android/pull/1525" - "1525" would be the input.
gcpr() {
PR="$GIT_SHORTCUTS_REPO/pull/$1"
git checkout $PR
}
# ~~~ SCRIPTS ~~~
loop_diff() {
while :
do
echo ". . . . . . . . . . . . . . . . . . . . . . . ."
git diff --name-status
sleep $LOOP_STATUS_INTERVAL
done
}