This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit.sh
151 lines (140 loc) · 3.71 KB
/
git.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Interactive helper functions/aliases around git.
export GIT_SOURCE_DATA="/usr/local/src/git/share"
###
# Outputs the current branch in the current directory.
# Arguments:
# None
# Outputs:
# Current local branch name of HEAD
# Returns:
# 1, if the underlying git command failed, 0 otherwise
###
alias gitbr="git rev-parse --abbrev-ref HEAD"
###
# Pulls all branches and rebases the commits on the working changes.
# Arguments:
# None
# Outputs:
# Nothing
# Returns:
# 1, if the underlying git command failed, 0 otherwise
###
alias gitpb="git pull --rebase"
###
# Attempts to pulls all branches and cancels the action on existing working changes.
# Arguments:
# None
# Outputs:
# Nothing
# Returns:
# 1, if the underlying git command failed (i.e. when working changes are available), 0 otherwise
###
alias gitpf="git pull --ff-only"
###
# Pushes all branches to the remote.
# Arguments:
# None
# Outputs:
# Nothing
# Returns:
# 1, if the underlying git command failed, 0 otherwise
###
alias gitpa="git push --all"
###
# Ammends the working changes into the last commit.
# # Arguments:
# None
# Outputs:
# Nothing
# Returns:
# 1, if the underlying git command failed, 0 otherwise
###
alias gitam="git commit --amend --no-edit"
###
# Finds all commits of all branches with a given string in the description.
# Arguments:
# $1 - Fulltext search text for all commits
# Outputs:
# Verbose information about the result
# Returns:
# 1, if the query failed or nothing was found, 0 otherwise
###
gitfind() {
if [ $# -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Finds all commits of all branches with a given string in the description."
echo "Usage: gitfind <search>"
echo ""
return 1
fi
git log -G"$1" -p --all
}
###
# Commits the current working changes using semantic commit messages.
# Arguments:
# $1 - Semantic scoped verb [ feat | fix | docs | style | refactor | test | chore ][!][@<scope>]?
# $* - Commit message
# Outputs:
# Verbose information or error
# Returns:
# 1, if the query failed or nothing was found, 0 otherwise
###
gitco() {
if [ $# -lt 2 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Commits the current working changes using semantic commit messages."
echo "Usage: gitco [ feat | fix | docs | style | refactor | test | chore ][!][@<scope>]? <...message>"
echo ""
return 129
fi
verb="$(echo $1 | cut -d'@' -f1)"
scope="$(echo $1 | cut -d'@' -f2)"
if [ -n "$scope" ]; then
if ! [ "$verb" = "$scope" ]; then
verb="$verb($scope)"
fi
fi
shift
git commit -m "$verb: $*"
}
###
# Merges the current branch into the given branch.
# Repository must not have working changes active.
# Arguments:
# $@ - Branchnames of the branches to merge into
# Outputs:
# Verbose information or error
# Returns:
# 1, if the merge failed, 0 otherwise
###
gitfuse() {
if [ $# -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Merges the current branch into the given branch."
echo "Usage: gitfuse <into_branch...>"
echo ""
return 129
fi
current_branch="$(git rev-parse --abbrev-ref HEAD)"
for branch in "$@"; do
if [ "$branch" != "$current_branch" ]; then
git checkout $branch && git merge $current_branch
fi
done
git checkout $current_branch
}
###
# Finds all commits of all branches with a given string in the description.
# Arguments:
# $1 - Fulltext search text for all commits
# Outputs:
# Verbose information about the result
# Returns:
# 1, if the query failed or nothing was found, 0 otherwise
###
gitfind() {
if [ $# -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Finds all commits of all branches with a given string in the description."
echo "Usage: gitfind <search>"
echo ""
return 129
fi
git log -G"$1" -p --all
}