Skip to content

Instantly share code, notes, and snippets.

@slattery
Last active August 29, 2015 14:27
Show Gist options
  • Save slattery/e5c58b7b6fa3ffc04928 to your computer and use it in GitHub Desktop.
Save slattery/e5c58b7b6fa3ffc04928 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Execute as a bash file, so no copy-paste in your terminal please.
# clear meaningless config settings
git config --global --remove-section apply
# aliases for basic commands
git config --global alias.st status
git config --global alias.ci commit
git config --global alias.co checkout
git config --global alias.br branch
# Show branch heads that are (not) in default branches
git config --global alias.notinpreview 'branch -r --no-merged origin/preview'
git config --global alias.notinlive 'branch -r --no-merged origin/live'
git config --global alias.notinrelease 'branch -r --no-merged origin/release'
git config --global alias.inpreview 'branch -r --merged origin/preview'
git config --global alias.inlive 'branch -r --merged origin/live'
git config --global alias.inrelease 'branch -r --merged origin/release'
# pretty log formatting
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
# aliases for workflow 2.0
# usage: git new BRANCHNAME-123
git config --global alias.new '!sh -c "git checkout start && git pull --rebase origin live && git checkout -b $1"'
# aliases for preview branch rebuilding and branch comparison
git config --global alias.oneline '!_() { $(test $# -eq 0 && echo xargs -L1) git log --no-walk --decorate --oneline "$@"; }; _'
git config --global alias.tips '!_() { t=$(git rev-list --no-merges --max-count=1 "$@"); if test -n "$t"; then echo $t; _ "$@" ^$t; fi; }; _'
git config --global alias.view '!git tips origin/preview ^origin/live | git oneline'
git config --global alias.rebuild-preview '!git checkout preview && git reset --hard origin/live && git merge --no-ff `git tips origin/preview ^origin/live | tr "\n" " "`'
# Auto-merge origin/<branch> into preview & release
git config --global alias.preview '!sh -c "git push origin $@ && git checkout preview && git fetch && git reset --hard origin/preview && git merge origin/$@ && git push && git checkout $@"'
git config --global alias.release '!sh -c "git checkout release && git pull && git merge origin/$@ && git push"'
git config --global alias.hotfix '!sh -c "git push origin $@ && git checkout live && git pull && git merge origin/$@ && git push"'
# colored terminal output
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
git config --global color.interactive auto
git config --global color.ui auto
git config --global color.grep always
# define global ignore file (use this for /.idea and .DS_Store files)
git config --global core.excludesfile ~/.gitignore
git config --global core.attributesfile ~/.gitattributes
# set vim as default editor
git config --global core.editor vim
git config --global core.eol lf
git config --global core.ignorecase false
# set default template dir
git config --global init.templatedir ~/.git_template
# only push current branch on git push unless explicitly defined otherwise
git config --global push.default current
# set merge default to --no-ff
git config --global merge.ff false
# populate the log message with one-line commit descriptions
git config --global merge.log true
# automatically set local settings when checking out a remote branch
git config --global branch.autosetupmerge true
git config --global branch.start.autosetupmerge false
git config --global branch.live.autosetupmerge false
git config --global branch.release.autosetupmerge false
git config --global branch.preview.autosetupmerge false
# set default pull to pull --rebase, prevent pull from merging for auto setup branches
git config --global branch.autosetuprebase remote
# global config for branches called 'start' (rebase on live when pulling)
git config --global branch.start.merge refs/heads/live
git config --global branch.start.remote origin
git config --global branch.start.rebase true
# global config for branches called 'live'
git config --global branch.live.remote origin
git config --global branch.live.merge refs/heads/live
git config --global branch.live.rebase true
# global config for branches called 'preview'
git config --global branch.preview.merge refs/heads/preview
git config --global branch.preview.remote origin
git config --global branch.preview.rebase true
# global config for branches called 'release'
git config --global branch.release.remote origin
git config --global branch.release.merge refs/heads/release
git config --global branch.release.rebase true
#!/bin/bash
# Based on: https://github.com/niden/Git-Pre-Commit-Hook-for-certain-words
checks[1]="var_dump("
checks[2]="print_r("
checks[3]="die"
checks[4]="console\.log"
element_count=${#checks[@]}
let "element_count = $element_count + 1"
ROOT_DIR="$(pwd)/"
LIST=$(git status | grep -e '\#.*\(modified\|added\)')
ERRORS_BUFFER=""
$(echo git status)
echo
echo "--- Validating your changes ---"
echo
for file in $LIST
do
if [ "$file" == '#' ]; then
continue
fi
if [ $(echo "$file" | grep 'modified') ]; then
FILE_ACTION="modified"
elif [ $(echo "$file" | grep 'added') ]; then
FILE_ACTION="added"
else
EXTENSION=$(echo "$file" | grep ".php\|.phtml\|.js$")
if [ "$EXTENSION" != "" ]; then
index=1
while [ "$index" -lt "$element_count" ]
do
#echo "Checking $FILE_ACTION file: $file [${checks[$index]}]"
ERRORS=$(grep -rnie "${checks[$index]}" $ROOT_DIR$file >&1)
if [ "$ERRORS" != "" ]; then
if [ "$ERRORS_BUFFER" != "" ]; then
ERRORS_BUFFER="$ERRORS_BUFFER\n$file:$ERRORS"
else
ERRORS_BUFFER="$file:$ERRORS"
fi
fi
let "index = $index + 1"
done
fi
fi
done
if [ "$ERRORS_BUFFER" != "" ]; then
echo
echo -e "These errors were found in try-to-commit files: "
echo -e $ERRORS_BUFFER
echo
echo -e "Can't commit, fix errors first."
exit 1
else
echo "Commited successfully."
#!/usr/bin/env ruby
#
# Git commit-msg hook. Prepend branch name to commit tasks.
# If your branch name is in the numeric form "12345", also prepend "(Task 123)" to commit messages,
# unless #noticket is included in the message (#notask will be stripped).
#
# Based on git://gist.github.com/750755.git
branchname = `git branch --no-color 2> /dev/null`[/^\* (.+)/, 1].strip
message_file = ARGV[0]
message = File.read(message_file).strip
prepend = "[#{branchname}] +: "
# When task branch name is numeric and not a merge, use it for ticket number
if branchname =~ /\d+/ && (message =~ /Merge branch.*into #{branchname}/).nil?
task_number = branchname.gsub(/[^\d]/, '')
prepend += "(Ticket #{task_number}) "
end
# When message is blank and starts with comments, add a line break
prepend += "\n" if message.chars.first == "#"
if message.include?("#noticket")
message.sub!(/^\s*#noticket\s*|\s*#noticket/, '')
else
message = prepend + message
end
File.open(message_file, 'w') {|f| f.write message }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment