Skip to content

Instantly share code, notes, and snippets.

@pbchase
Last active March 25, 2022 15:00
Show Gist options
  • Save pbchase/3658955e405378dc66ed4929c739a464 to your computer and use it in GitHub Desktop.
Save pbchase/3658955e405378dc66ed4929c739a464 to your computer and use it in GitHub Desktop.
A pair of BASH functions to push and pull branches and tags as part of a Fit Flow workflow
# gfpull_gfpush.sh
# A pair of BASH functions to push and pull branches and tags as part of a Fit Flow workflow
# gfpull is useful for updating my local branches and tags in a Git Flow repo before branching or doing code review.
# When origin does not point at the correct upstream remote, specify the remote at the first parameter.
# When their are gitflow lineages in the same repo, you can specify a prefix for the branches in the second parameter
function gfpull {
if [ -z "$1" ]; then
REMOTE=origin
else
REMOTE=$1
fi
if [ -z "$2" ]; then
PREFIX=""
else
PREFIX=$2
fi
git checkout ${PREFIX}master && git pull $REMOTE ${PREFIX}master
git checkout ${PREFIX}main && git pull $REMOTE ${PREFIX}main
git checkout ${PREFIX}develop && \
git pull $REMOTE ${PREFIX}develop && \
git pull --tags $REMOTE
}
# gfpush is useful for pushing my local branches and tags in a Git Flow repo after a release
# When origin does not point at the correct upstream remote, specify the remote at the first parameter.
# When their are gitflow lineages in the same repo, you can specify a prefix for the branches in the second parameter
function gfpush() {
if [ -z "$1" ]; then
REMOTE=origin
else
REMOTE=$1
fi
if [ -z "$2" ]; then
PREFIX=""
else
PREFIX=$2
fi
git checkout ${PREFIX}master && git push $REMOTE ${PREFIX}master
git checkout ${PREFIX}main && git push $REMOTE ${PREFIX}main
git checkout ${PREFIX}develop && \
git push $REMOTE ${PREFIX}develop && \
git push --tags $REMOTE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment