-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-checkpush
28 lines (22 loc) · 859 Bytes
/
git-checkpush
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
#!/bin/sh
newBranch=$1
test -z $newBranch && echo "ERROR: Please provide the name of the new branch you'd like to create, using the standard {bug || feature}/{workItemId}-{description}" 1>&2 && exit 1
if currentBranch=$(git symbolic-ref --short -q HEAD)
then
echo "Branching from $currentBranch to $newBranch"
git stash
git checkout -b $newBranch
remoteOrigin=$(git config --get remote.origin.url)
echo Remote is $remoteOrigin
if [ $(git ls-remote --heads $remoteOrigin $newBranch + | wc -l) == "1" ]
then
echo "Remote branch exits. Pull changes from remote before pushing the changes."
git pull --rebase origin $newBranch
else
echo "Setting $newBranch to upstream"
git push --set-upstream origin $newBranch
fi
# Apply the stashed changes
git stash apply
echo "Successfully pushed the updates to remote!"
fi