Skip to content

Instantly share code, notes, and snippets.

@Glutnix
Last active July 23, 2020 23:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Glutnix/163d35d5e37cbbb8f26fc9c4515727a5 to your computer and use it in GitHub Desktop.
Save Glutnix/163d35d5e37cbbb8f26fc9c4515727a5 to your computer and use it in GitHub Desktop.
Git Aliases
[core]
autocrlf = true
excludesfile = C:\\Users\\Brett\\Documents\\gitignore_global.txt
# Git Extensions built-in commit editor
#editor = \"C:/Program Files (x86)/GitExtensions/GitExtensions.exe\" fileeditor
# Use Visual Studio Code
editor = code -w
longpaths = true
[init]
templatedir = ~/.git_template
[user]
name = Brett Taylor
email = brett@webfroot.co.nz
signingKey = ""
[push]
default = simple
[branch]
autosetuprebase = always
[color]
ui = true
[alias]
ec = config --global --edit # Edit global git Config
la = !git config -l | grep alias | cut -c 7- # List Aliases
l = log --pretty=format:%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn] --decorate --date=short
lg = log --oneline --decorate --all --graph # Log Graph
lt = log --graph --decorate --pretty=format:'%C(yellow)%h%Creset%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset'
b = branch
a = add
ap = add -p # Add Parts
s = status -s
st = status -s
c = commit --verbose
up = push -u origin HEAD # "get up, get on up"
pushit = push -u origin HEAD --force-with-lease # "push it real good!"
# Many of these are from: https://haacked.com/archive/2014/07/28/github-flow-aliases/
co = checkout
cob = checkout -b # CheckOut Branch
cm = !git add -A && git commit --verbose # Commit all with Message
save = !git add -A && git commit -m 'SAVEPOINT' # include all untracked files
wip = !git add -u && git commit -m 'WIP' # include only tracked files
undo = reset HEAD~1 --mixed # your last commit, undone and ready to redo
amend = commit -a --amend # amend the last commit, including tracked file modifications
wipe = !git add -A && git commit -qm 'WIPE SAVEPOINT' && git reset HEAD~1 --hard # safer `git reset HEAD --hard`
optimize = "!git optimise"
optimise = "!git remote prune origin && git bclean && git prune && git deep-repack"
deep-repack = !git repack -a -d --depth=250 --window=250
bclean = "!f() { git branch --merged ${1-master} | grep -v " ${1-master}$" | xargs -r git branch -d; }; f" # delete merged branches
bdone = "!f() { git checkout ${1-master} && git upd && git bclean ${1-master}; }; f" # "branch done!" go to master, pull, and delete merged branches
upd = !git pull --rebase --prune $@ && git submodule update --init --recursive
# https://haacked.com/archive/2015/06/29/git-migrate/
# migrate {new-branch} [target-branch] [commit-range]: move commits on current branch to new branch name.
migrate = "!f(){ CURRENT=$(git symbolic-ref --short HEAD); git checkout -b $1 && git branch --force $CURRENT ${3-'$CURRENT@{u}'} && git rebase --onto ${2-master} $CURRENT; }; f"
# use Paul Irish's git-open: https://github.com/paulirish/git-open
browse = !git open
gh = !git open
[merge]
# this is the tool that will be used when using `git mergetool`
tool = bc3
[diff]
# this is the tool that will be used when using `git difftool`
tool = bc3
guitool = bc3
[mergetool "bc3"]
trustExitCode = true
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[gpg]
program = gpg
[commit]
gpgSign = false
[tag]
forceSignAnnotated = false
[credential "helperselector"]
selected = wincred
#!/bin/bash
# Stops accidental commits to master and develop. https://gist.github.com/stefansundin/9059706
BRANCH=`git rev-parse --abbrev-ref HEAD`
if [[ "$BRANCH" == "master" ]]; then
echo "You are on branch $BRANCH. Are you sure you want to commit to this branch?"
echo "If so, commit with -n to bypass this pre-commit hook."
exit 1
fi
exit 0
#!/bin/bash
# Pre-fills commit message with Jira issue codes
branchPath=$(git symbolic-ref -q HEAD) # something like refs/heads/XX-12345-myBranchName
branchName=${branchPath##*/} # get text behind the last / of the branch path
issueCode=`expr match "$branchName" '\([a-zA-Z]\+-[0-9]\+\)'` # extract the jira issue code
firstLine=$(head -n1 $1)
if [ -z "$firstLine" ] ;then # check that this is not an amend by checking that the first line is empty
sed -i "1s/^/$issueCode /" $1 # insert branch code at the start of the commit message file
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment