Skip to content

Instantly share code, notes, and snippets.

@cshireman
Created August 15, 2014 18:57
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 cshireman/38d9299db41291f2fbec to your computer and use it in GitHub Desktop.
Save cshireman/38d9299db41291f2fbec to your computer and use it in GitHub Desktop.
BASH: Phabricator workflow bash functions
RELEASE_BRANCH=release/v2.0.0
# Shortcut replacement for fetching and rebasing into your current branch. This can be used either as a substitute for git pull, or a way to rebase changes from the primary branch into your local feature/bug branch.
# $1 = either 'dev' or 'rel' depending on which branch you want to rebase into your branch. If it is neither 'dev' or 'rel' then it should be a remote branch you want to rebase into your branch (e.g. origin/branch_name)
#
# Example usage: gitup dev
# Example usage: gitup rel
# Example usage: gitup origin/branch_name
gitup()
{
if [ "$#" -ne "1" ] # If there isn't exactly one argument
then
echo "Usage: 'gitup [dev/rel]' or 'gitup {branch-name}'" # Bail out with bad arguments
kill -INT $$
fi
if [ "$1" = "dev" ] # If they specify development
then
git fetch && git rebase origin/develop
elif [ "$1" = "rel" ] # If they specify release
then
git fetch && git rebase origin/$RELEASE_BRANCH
else # Otherwise they should have specified a remote branch
git fetch && git rebase $1
fi
}
# Shortcut replacement for creating a new branch.
# $1 = new branch name
# $2 = either 'dev' or 'rel' depending on which branch you want to rebase into your branch. If it is neither 'dev' or 'rel' then it should be a remote branch you want to rebase into your branch (e.g. origin/branch_name)
#
# Example usage: gitcb branch_name origin/develop
gitcb()
{
if [ "$#" -ne "2" ] # If there isn't exactly one argument
then
echo "Usage: 'gitcb {new-branch} [dev/rel]' or 'gitcb {new-branch} {master-branch-name}'" # Bail out with bad argument
kill -INT $$
fi
git fetch # Fetch latest data from the repo
if [ "$2" = "dev" ] # If they specify development
then
git checkout -b $1 origin/develop
elif [ "$2" = "rel" ] # If they specify release
then
git checkout -b $1 origin/$RELEASE_BRANCH
else # Otherwise they should have specified a remote branch
git checkout -b $1 $2
fi
}
# Shortcut for creating a codereview in Phabricator
# $1 = either 'dev' or 'rel' depending on which branch you want to rebase into your branch. If it is neither 'dev' or 'rel' then it should be a remote branch you want to rebase into your branch (e.g. origin/branch_name)
#
# Example usage: cr dev
# Example usage: cr rel
# Example usage: cr origin/branch_name
cr()
{
if [ "$#" -ne "1" ] # If there isn't exactly one argument
then
echo "Usage: 'cr [dev/rel]' or 'cr {branch-name}'" # Bail out with bad argument
kill -INT $$
fi
gitup $1 # Update local branch to the most recent stuff from the remote branch
if [ "$1" = "dev" ] # If they specify development
then
arc diff origin/develop
elif [ "$1" = "rel" ] # If they specify release
then
arc diff origin/$RELEASE_BRANCH
else # Otherwise they should have specified a remote branch
arc diff $1
fi
}
# Shortcut for the merge command we must do to bring our latest changes on the release branch into develop
# You must still do a push after executing this command
reltodev()
{
git checkout develop
gitup dev
git merge --no-ff $RELEASE_BRANCH -m "Release Fix: Merge from $RELEASE_BRANCH"
}
@cshireman
Copy link
Author

Thanks to DJM for cleaning this up and making it more user friendly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment