Speedy Git

Paul McGrath

@blorgfester

Why are we here?

Git is powerful and very fast

Our primary function is programming

A little bit of git knowledge pays dividends

Difficult?

"git is harder to learn than the programming" - Someone on twitter

Scary?

"It just disappears into git and then who knows where it goes?" - A colleague

My first job (17 years old)

User interface 1.0

User interface 2.0

Speedy Input

Git Aliases

[alias]
	st = status
	ru = remote update --prune
	cm = commit -m
	co = checkout
	au = add -u
	aa = add -A
	ai = add -i
	cu = clean -d -fx
	pr = pull --rebase
	po = push origin master
	mnff = merge --no-ff
	fo = fetch origin
	su = !git submodule sync && git submodule update --init --recursive
	cos = "!f(){ git co "$1" && git su; };f"

In ~/.gitconfig:

Url for a copy of my .gitconfig:(https://sciphus.com/gitconfig)

Speedy Commiting

Use your favourite editor

git config --global core.editor notepad
git config --global core.editor "code --wait"

Speedy Visualisation

A better log

git log is not so readable

A better log

git log --graph --decorate --oneline --date=relative --all

Use your favourite log viewer

Use your favourite log viewer

tlog()
{
	tortoisegitproc /command:log /path:. &
}
exp()
{
	explorer . &
}

In ~/.bashrc

Visual merge tools

Visual merge tools

Where was this bug introduced

git bisect to the rescue

Rebasing

  • Amending work
  • Reordering stuff
  • Squashing

git rebase --interactive

Interactive rebase

Small, frequent commits

  • Fewer merge conflicts
  • Easier to reason about
  • Can always be squashed
    • with git rebase --interactive

Git Hooks

Git Hooks

  • Samples can be found in .git/hooks
  • Simple CLI programs in Bash, Ruby, Python, etc with #!/bin/python

 

pre-commit

  • Check coding standards
  • Run tests
  • Check for typos

pre-push

Client side hooks

Server Side Hooks

(post-receive)

Create a bare repository in ~/deployment

A add the post-receive hook:

#!/bin/bash

echo "Changes received - Deploying to production..."
git --work-tree=/var/www/html --git-dir=/home/deployment checkout -f

On your machine, add the remote:

git remote add production <you>@<yourwebhost>:~/deployment

The reflog

Resetting to the previous commit:

git reset --hard master@{1}

git reset --hard @{1}
git config --global alias.undo '!f() { git reset --hard @{1}; }; f'
git config --global alias.undo '!f() { git reset --hard @{${1-1}}; }; f'

Speedy Git

https://sciphus.com/speedygit.html

@blorgfester