-
-
Save andjc/e9804b7f41752edc377142afcf955cd3 to your computer and use it in GitHub Desktop.
Aliases for Git Bash - handy functions for common tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# generated by Git for Windows | |
test -f ~/.profile && . ~/.profile | |
test -f ~/.bashrc && . ~/.bashrc | |
_gitzip(){ | |
CURRDATE=`date +%Y%m%d` | |
NAME=${PWD##*/} | |
ARG=$1 | |
LAST_COMMIT=$2 | |
BACKUP_DIR="deployment_backup" | |
if [ ! -z "$ARG" ] | |
then | |
ARG=`echo $ARG | iconv -t ascii//TRANSLIT | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z` | |
else | |
ARG=`git rev-parse --abbrev-ref HEAD` | |
fi | |
if [ -z "$LAST_COMMIT" ] | |
then | |
LAST_COMMIT="HEAD^" | |
fi | |
if [ ! -d "$BACKUP_DIR" ]; then | |
mkdir $BACKUP_DIR | |
fi | |
git diff --name-only --diff-filter=ACMRT $LAST_COMMIT..HEAD ':(exclude)*.vb' ':(exclude)*.config' ':(exclude)*.vbproj' ':(exclude)*.cs' ':(exclude)*.csproj' | xargs -I % cp --parents % $BACKUP_DIR | |
git diff --name-only -z --diff-filter=ACMRT $LAST_COMMIT..HEAD ':(exclude)*.vb' ':(exclude)*.config' ':(exclude)*.vbproj' ':(exclude)*.cs' ':(exclude)*.csproj' | xargs -0 git archive -o /d/dev/push/$CURRDATE-$NAME-$ARG.zip HEAD -- | |
zip -uqr /d/dev/push/$CURRDATE-$NAME-$ARG.zip $BACKUP_DIR | |
rm -rf $BACKUP_DIR | |
} | |
# Creates a new site in IIS, based on the current repo name. | |
# You will need to either run Git Bash as an admin, or grant your | |
# user account write access to the following locations: | |
# C:\windows\system32\inetsrv\config | |
# C:\windows\system32\drivers\etc\hosts | |
_addSite(){ | |
# Get the current top-level directory for the REPO | |
DIR=`git rev-parse --show-toplevel` | |
# Reverse the slashes since IIS is picky about that | |
DIR=${DIR//\//\\} | |
# Get the repo name | |
REPO=`basename $DIR` | |
# Get the current timestamp - used for the IIS site ID | |
TS=`date +%s` | |
if [ ! -z "$REPO" ] | |
then | |
# Make sure that the site does not already exist | |
EXISTS=`"c:\windows\system32\inetsrv\appcmd" list site /name:"$REPO.local"` | |
if [ -z "$EXISTS" ] | |
then | |
echo "Creating site $REPO.local" | |
"c:\windows\system32\inetsrv\appcmd" add site /name:$REPO.local /id:$TS /physicalPath:$DIR /bindings:http/*:80:$REPO.local | |
echo "127.0.0.1 $REPO.local" >> /c/windows/system32/drivers/etc/hosts | |
echo "Added hosts file entry for $REPO.local." | |
else | |
echo "$REPO.local already exists." | |
fi | |
fi | |
} | |
# Shortcut to clone from MERGE Atlanta Gitlab repos | |
_mergeClone(){ | |
ARG=$1 | |
if [ ! -z "$ARG" ] | |
then | |
REPO="[email protected]:avid-design/$ARG" | |
git clone $REPO | |
else | |
echo "You must provide a repo name." | |
fi | |
} | |
alias gitzip='_gitzip' | |
alias addsite='_addSite' | |
alias gc='_mergeClone' | |
alias unmerged='git branch -a --no-merged | grep -v HEAD | xargs -L1 git --no-pager log --pretty=tformat:'"'"'%Cgreen%d%Creset - %h by %an (%Cblue%ar%Creset)'"'"' -1' | |
alias merged='git branch -a --merged | grep -v HEAD | xargs -L1 git --no-pager log --pretty=tformat:'"'"'%Cgreen%d%Creset - %h by %an (%Cblue%ar%Creset)'"'"' -1' | |
alias unmergedr='git branch -r --no-merged | grep -v HEAD | xargs -L1 git --no-pager log --pretty=tformat:'"'"'%Cgreen%d%Creset - %h by %an (%Cblue%ar%Creset)'"'"' -1' | |
alias mergedr='git branch -r --merged | grep -v HEAD | xargs -L1 git --no-pager log --pretty=tformat:'"'"'%Cgreen%d%Creset - %h by %an (%Cblue%ar%Creset)'"'"' -1' | |
alias mrmsg='git log develop.. --abbrev-commit --pretty=format:"- %s"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment