-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgit-repush
More file actions
executable file
·33 lines (23 loc) · 767 Bytes
/
Copy pathgit-repush
File metadata and controls
executable file
·33 lines (23 loc) · 767 Bytes
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
#!/bin/bash
# Deletes a remote branch and then pushes it again.
# Useful when force-pushes are not allowed and you want to rebase
BRANCH=${1:-`git rev-parse --abbrev-ref HEAD`}
branch_exists () {
git rev-parse --abbrev-ref $1 &>/dev/null && echo 1
}
if [[ $(branch_exists $BRANCH) -ne 1 ]]; then
echo "Branch $BRANCH does not exist."
exit 1
fi
echo "Publishing $BRANCH..."
git fetch origin
if [[ $BRANCH == 'master' || $BRANCH == 'trunk' || $BRANCH == '' || $(echo $BRANCH) == '' ]]; then
echo "$BRANCH? Nope."
exit 1
fi
read -p "Overwrite origin/$BRANCH? [Y/n] " -n 1 -r; echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi
if [[ $(branch_exists origin/$BRANCH) ]]; then
git push origin --delete $BRANCH
fi
git push -u origin $BRANCH