Skip to content

Instantly share code, notes, and snippets.

@waleedsamy
Last active February 17, 2016 14:15
Show Gist options
  • Select an option

  • Save waleedsamy/921294a0e5bdd49cf4c4 to your computer and use it in GitHub Desktop.

Select an option

Save waleedsamy/921294a0e5bdd49cf4c4 to your computer and use it in GitHub Desktop.
git fresh version of a branch
###
## install: curl https://gist.githubusercontent.com/waleedsamy/921294a0e5bdd49cf4c4/raw/e3ccf5123f49cd70af542e6de077995f9b040f4b/regit.sh > ~/regit.sh && chmod +x ~/regit.sh
## usage: ~/regit.sh master
###
regit(){
if [ $# -eq 1 ]
then
project=${PWD}
brnch=$1
tmp="$RANDOM-tmp"
cd $project && git reset --hard HEAD
if [[ `git branch --list $brnch` ]] # require git +2v
then
git checkout -b $tmp && git branch -D $brnch
fi
git fetch origin $brnch:$brnch
if [[ `git branch --list $tmp` ]] # require git +2v
then
git checkout $brnch && git branch -D $tmp
fi
else
echo "usage: regit branch"
return 1
fi
}
regit $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment