-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitHelper.bsh
executable file
·112 lines (100 loc) · 3.57 KB
/
gitHelper.bsh
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
#!/bin/bash
#author: Jeffrey DeYoung
#to use, add to your shells .zshrc or .bashrc file. Ex: source ~/projects/linux-helpers/gitHelper.bsh
#git adds all files, then commits them;
#the comment for the commit will be the name of the git branch you are currently on
#prepended to the string you pass in as an argument to this function
function gcommit(){
git add -A
git commit -m "$(getGitBranch) -- $1"
}
#gets the current git branch you are on
function getGitBranch(){
git status | sed -n "1p" | awk -F' ' '{ print $3 }'
}
#checks out master, pulls, returns you to your branch, then merges master to your branch
function gitUpdateFromMaster(){
current=$(getGitBranch)
echo "checking out master from $current"
git checkout master
git pull
echo "checking out $current from master"
git checkout $current
git merge master
}
#takes your current branch, merges it to master, then pushes
function gitPushToMaster(){
current=$(getGitBranch)
echo "checking out master from $current"
git checkout master
echo "merging branch $current to master"
git merge work
git push
echo "checking out $current from master"
git checkout $current
}
#commits all current files with the comment passed in; pushes to remote
function commitAndPushToCurrentBranch(){
gcommit $1
git push
}
#checks out master and pulls latest
function getCheckoutMasterAndPull(){
echo "checking out master and pulling"
git checkout master && git pull
}
#java start new work -- builds, checks out a new branch, pushes to origin, upticks, and does an inital commit
#Note: Requires the javaMinorVersionUptick script to be sourced
function javaStartNewWork(){
echo "Starting java work on a new branch $1"
getCheckoutMasterAndPull
#make sure the current master builds so we don't start off on a bad foot with our new branch
mvn clean install
if [ $? -eq 0 ]
then
echo "Master Build Success! Checking out new branch."
git checkout -b $1
git push -u origin $1
javaMinorVersionUptick
git commit -a -m "Start of work on $1 -- uptick only."
else
echo "Could not build master; please ensure that works prior to starting new work."
fi
}
#starts a new branch with the passed in name, and pushes it to create it on origin
function startNewWork(){
echo "Starting work on a new branch $1"
getCheckoutMasterAndPull
git checkout -b $1
git push -u origin $1
}
#goes it to all top-level git projects in the current dir and pulls (not changing the currently checked out branch)
function pullAll(){
echo "Updating all top-level directories."
for d in ./*/ ; do (cd "$d" && echo "Pulling dir $d" && git pull); done
}
#goes it to all top-level git projects in the current dir, checks out master and pulls (leaving the project on master)
function pullFromMasterAll(){
echo "Updating all top-level directories to master."
for d in ./*/ ; do (cd "$d" && echo "Pulling dir $d" && getCheckoutMasterAndPull); done
}
#git update from master
alias gufm="gitUpdateFromMaster"
#git push to master
alias gptm="gitPushToMaster"
#git add and commit
alias gac="git add -A; gcommit"
#git add, commit, and push
alias gacp="commitAndPushToCurrentBranch"
#git checkout master and pull
alias gcm="getCheckoutMasterAndPull"
#git pull (i'm lazy, ok?)
alias gp="git pull"
#git pull all
alias gpa="pullAll"
#git pull all from master
alias gpam="pullFromMasterAll"
#java start new work -- builds, checks out a new branch, pushes to origin, upticks, and does an inital commit -- must pass in a new branch name
alias jsnw="javaStartNewWork"
#start new work -- must pass in a new branch name
alias snw="startNewWork"