Last active
August 29, 2015 14:03
-
-
Save pik4ez/2a2f9e6117f9ae7d6691 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function usage { | |
echo "Replaces branch with tag in local and remote repos." | |
echo | |
echo "Usage:" | |
echo " $0 <remote> <branch>" | |
} | |
if [ -z "$1" ]; then | |
usage | |
echo | |
echo "ERROR" | |
echo "No remote specified" | |
exit 1 | |
fi | |
remote="$1" | |
if [ -z "$2" ]; then | |
usage | |
echo | |
echo "ERROR" | |
echo "No branch specified" | |
exit 1 | |
fi | |
branch="$2" | |
tag="$2" | |
git status &> /dev/null | |
if [[ "$?" > 0 ]]; then | |
echo "ERROR" | |
echo "Not in git repository" | |
exit 1 | |
fi | |
cur_branch=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD) | |
git checkout "$branch" &> /dev/null | |
if [[ "$?" > 0 ]]; then | |
echo "ERROR" | |
echo "Can't find branch with name $branch" | |
exit 1 | |
fi | |
git tag "$tag" | |
if [[ "$cur_branch" == "$branch" ]]; then | |
git checkout master &> /dev/null | |
else | |
git checkout "$cur_branch" &> /dev/null | |
fi | |
git branch -d "$branch" &> /dev/null | |
git push "$remote" ":$branch" &> /dev/null | |
git push "$remote" "$tag" &> /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment