Skip to content

Instantly share code, notes, and snippets.

@aj-adl
Created February 13, 2018 06:51
Show Gist options
  • Save aj-adl/5fb70d6d65f581c04cacaacc940a026f to your computer and use it in GitHub Desktop.
Save aj-adl/5fb70d6d65f581c04cacaacc940a026f to your computer and use it in GitHub Desktop.
Command to automate branch switching and merging when using deployment braches
#!/usr/bin/env bash
function gdpl (){
set -e
local RED=`tput setaf 1`
local GREEN=`tput setaf 2`
local BLUE=`tput setaf 6`
local YELLOW=`tput setaf 3`
local PURPLE=`tput setaf 5`
local NC=`tput sgr0` # No Color
local TAG="${BLUE}FRAME TOOLSET ${NC}:::: "
local NL=`tput il 1`
if [ $# -eq 0 ]; then
echo "${RED}Please supply a valid branch";
exit 1;
fi;
echo "";
echo "";
echo "${TAG}${YELLOW}Checking out branch \"${1}\"";
echo "${NC}................................";
echo "";
echo "";
git checkout $1;
git pull origin $1;
if [ $# -eq 2 ]; then
echo "";
echo "";
echo "${TAG}${YELLOW}Merging branch \"${2}\" into branch \"${1}\"";
echo "${NC}................................";
echo "";
echo "";
git merge $2;
else
echo "";
echo "";
echo "${TAG}${YELLOW}Merging branch \"master\" into branch \"${1}\" ";
echo "${NC}................................";
echo "";
echo "";
git merge master;
fi;
echo "";
echo "";
echo "${TAG}${YELLOW}Merge complete! pushing to origin / ${1} ";
echo "${NC}................................";
echo "";
echo "";
git push origin $1;
echo "";
echo "";
echo "${TAG}${GREEN}Push complete, returing you to branch \"master\" ";
echo "${NC}................................";
echo "";
echo "";
git checkout master;
}
@aj-adl
Copy link
Author

aj-adl commented Feb 13, 2018

Why not just use tags?
We'd fricken love to but our deploy tool doesn't support triggering deployments automatically via regex tag matching

How do I use it?

  • add to your bash includes ( ~/.functions, ~/.bash_rc whatevs floats your $BOAT )
  • Signature: gdpl ${target_branch} [ ${source_branch} ]
  • Defaults: Source branch defaults to master

Examples

# Merge masting into staging
gdpl staging

# Merge feature-1 into staging (and return to feature-1)
gdpl staging feature-1

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