Skip to content

Instantly share code, notes, and snippets.

@pik4ez
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pik4ez/2a2f9e6117f9ae7d6691 to your computer and use it in GitHub Desktop.
Save pik4ez/2a2f9e6117f9ae7d6691 to your computer and use it in GitHub Desktop.
#!/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