Skip to content

Instantly share code, notes, and snippets.

@cgrinaldi
Last active August 29, 2015 14:16
Show Gist options
  • Save cgrinaldi/e1d5464b823659fdcd75 to your computer and use it in GitHub Desktop.
Save cgrinaldi/e1d5464b823659fdcd75 to your computer and use it in GitHub Desktop.
Automate the process of creating a solution branch and pulling from remote repository
#!/bin/bash
localPATH=`pwd` # path of current directory
sep='---------------'
for d in */; do
echo $sep"Processing" $d$sep
d=`echo $d | sed s#/##` # remove trailing forward slash
remoteRepo="https://github.com/hackreactor/$d.git" # location of remote repo
git -C $localPATH/$d remote add upstream $remoteRepo # add remote repo as upstream
git -C $localPATH/$d checkout master # checkout master branch in current $d
firstCommit=`git -C $localPATH/$d rev-list HEAD | tail -n 1` # identify the first commit in master
git -C $localPATH/$d checkout $firstCommit # checkout first commit
git -C $localPATH/$d branch solution # create a solution branch if not present
git -C $localPATH/$d checkout solution # checkout solution branch
git -C $localPATH/$d pull upstream solution # pull from remote into solution
git -C $localPATH/$d checkout master # checkout master branch
echo -e "\n"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment