GIT scripts

Small GIT scripts to save some time in daily work.

Remove completely merged branches by filter

Teammates may forget to remove self branches from the server. Let's delete all of them.
("feature/" - from GIT flow)
git branch -a --merged develop | grep "remotes/origin/feature/" | \
    grep -Eo "feature/.+" | xargs -L 1 -I % git push origin :%
"feature/" - it's your preferable branch prefix.
This example works for remote branches. You may easily use it for local branches via changing "grep" parameter "remotes/origin/feature/".

Get all hashes by keywords

Get all hashes by keywords, e.g. issue key in JIRA or some another your tracker.
#!/bin/sh
# Command: git allhash
# Get all hashes filtered by of commit comment
if [ "$1" != "" ]; then
    OUT=$(git log --pretty=format:'%h' --reverse --grep $@)
    OUT=$(echo -e $OUT) #del line break
    echo ${OUT// /","}
else
    echo "Please set filter string as a first parameter."
    exit
fi

E.g.: find all hashed for issue PRJ-123.
$ git allhash PRJ-123

Remove tag completely

#!/bin/sh
# Command: git tag-remove
# Remove tag completely
if [ -z "$1" ] ; then
 echo error: Empty tag name; exit 1
fi
git tag -d $1 && git push origin :refs/tags/$1

Example, remove tag v1.0.0 locally and remotelly:
$ git tag-remove v1.0.0

Move tag to the current commit

#!/bin/sh
# Move tag to last commit
if [ -z "$1" ] ; then
 echo error: Empty tag name; exit 1
fi
git tag-remove $1 && git tag $1 && git push --tags
Example, move tag v1.0.0 to the current commit:
$ git tag-move v1.0.0

No comments: