Skip to content

Commit 62193d5

Browse files
author
oscarkramer
committed
Added convenience scripts for creating and removing git branches
1 parent a5da4e8 commit 62193d5

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

scripts/gcrbr.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
#----------------------------------------------------------------------------------
4+
# Git create branch. Also creates upstream origin/branch and switches to new branch
5+
#----------------------------------------------------------------------------------
6+
7+
if [ -z $1 ]; then
8+
echo; echo "git remove branch: need branch name."; echo
9+
exit 0
10+
fi
11+
12+
branchname=$1
13+
git checkout -b $branchname
14+
if [ $? -ne 0 ]; then
15+
echo; echo "Local branch not created."; echo
16+
exit 1
17+
fi
18+
git push -u origin $branchname
19+
if [ $? -ne 0 ]; then
20+
echo; echo "Remote branch not created."; echo
21+
exit 1
22+
fi
23+
echo; echo "Branch $branchname successfully created."; echo
24+
25+
exit 0
26+
27+
28+

scripts/grmbr.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
#----------------------------------------------------------------------------------
4+
# Git remove branch. Deletes local AND upstream origin/branch.
5+
#----------------------------------------------------------------------------------
6+
7+
if [ -z $1 ]; then
8+
echo; echo "git remove branch: need branch name."; echo
9+
exit 0
10+
fi
11+
12+
branchname=$1
13+
echo
14+
read -p "Are you sure you want to completely delete $branchname? [y/N]" yesno
15+
if [ -z $yesno ]; then
16+
yesno="no"
17+
fi
18+
19+
if [ $yesno == "y" ] || [ $yesno == "Y" ]; then
20+
git branch -d $branchname
21+
if [ $? -ne 0 ]; then
22+
echo; echo "Local branch not deleted."; echo
23+
exit 1
24+
fi
25+
git push origin --delete $branchname
26+
if [ $? -ne 0 ]; then
27+
echo; echo "Remote branch not deleted."; echo
28+
exit 1
29+
fi
30+
fi
31+
32+
echo; echo "Branch $branchname successfully removed."; echo
33+
exit 0
34+
35+
36+

0 commit comments

Comments
 (0)