-
Notifications
You must be signed in to change notification settings - Fork 1
/
gitfunctions.sh
executable file
·117 lines (92 loc) · 2.37 KB
/
gitfunctions.sh
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
#!/bin/bash
# Copyright 2020 yerlibilgin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#merge all the branches to the one specified
mergeall(){
if [ `checkbranch $1` = 1 ]
then
for _____mergeall in test release master bugfix hotfix
do
if [ `checkbranch $_____mergeall` = 1 ]
then
git checkout $_____mergeall
git merge $1
else
echo >&2 "No branch $_____mergeall. Skipping"
fi
done
#check out back to the original branch
git checkout $1
retval=0
else
echo >&2 "No branch with name $1"
retval=1
fi
return "$retval"
}
#is there a branch with the given name
checkbranch(){
git show-ref refs/heads/$1 > /dev/null
if [ $? = 0 ]
then
echo 1
else
echo 0
fi
}
getLocalBranches(){
git branch | awk '{sub(/((\*)|( |\t)+)*/, "", $0); print}'
}
setUpstream(){
if [ $# = 0 ]
then
echo >&2 "Please provide origin name"
return 1
fi
for _____glbbb in `getLocalBranches`
do
if [ `checkbranch $_____glbbb` = 1 ]
then
git branch --set-upstream-to=$1/$_____glbbb $_____glbbb
fi
done
return 0
}
function gitHistRemove(){
if [ $# = 0 ]
then
echo "Please specify the file name to be pruned"
return 1
fi
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch $1" --prune-empty --tag-name-filter cat -- --all
}
function gitGC(){
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
git reflog expire --expire=now --all
git gc --prune=now
}
function purgeTag(){
tag=$1
if [ $# != 1 ]
then
echo "Please specify the tag name"
return 1
fi
git tag -d $tag
git push --delete origin $tag
}
alias glg='git log --graph --abbrev-commit --all'
alias gca='git commit -a'
alias gitamend='git commit --amend --no-edit'
alias gsfor='git submodule foreach'