Short talk about Git best practices I held during a Lunch&Learn in our Milan office @Gild.
The session was interactive with lots of examples.
AGENDA:
- Using aliases for git commands
- Stats: my most used commands
- Useful list of git aliases
- Work scenarios
3. WHAT'S GIT?
Git: The Information Manager from Hell
$ git log e83c516
commit e83c5163316f89bfbde7d9ab23ca2e25604af290
Author: Linus Torvalds
Date: Thu Apr 7 15:13:13 2005 -0700
Initial revision of "git", the information manager from hell
Photo credits: http://www.slideshare.net/SeongJaePark1/deep-darkside-ofgit
4. AGENDA
Using aliases for git commands
Stats: my most used commands
Useful list of git aliases
Work scenarios
5. WHAT IS IT HARD ABOUT GIT COMMANDS?
Photo credits: http://www.makerscorner.co/2014/08/productivity-hacks-git-aliases/
6. USING ALIASES FOR GIT COMMANDS
$ git status -sb
$ s # alias s='git status -sb'
$ git add --all --patch
$ gap # alias gap='git add --all --patch'
$ git commit -v --amend
$ gcm # alias gcm='git commit -v --amend'
8. USEFUL LIST OF GIT ALIASES
Full list: colmarius/git-aliases.md
alias s='git status -sb'
alias ga='git add -A'
alias gap='ga -p'
alias gbr='git branch -v'
gc() {
git diff --cached | grep 'btap[ph]b' >/dev/null &&
echo "e[0;31;29mOops, there's a #tapp or similar in that diff.e[0m" ||
git commit -v "$@"
}
alias gch='git cherry-pick'
alias gcm='git commit -v --amend'
alias gco='git checkout'
9. WORK SCENARIO #1: FORGOT TO BRANCH!
Suppose we have a rule (which we do!),
called "branch-per-feature"
At some point... I start commiting my new
bug-fix/feature directly on master
Commit #1, #2, #3... :-/
10. WORK SCENARIO #1: FORGOT TO BRANCH!
$ git status -sb
## master...origin/master [ahead 3]
$ git checkout -b my-feature
Switched to a new branch 'my-feature'
$ git checkout -B master origin/master
Branch master set up to track remote branch master from origin.
Switched to and reset branch 'master'
Your branch is up-to-date with 'origin/master'.
Tip: branches are just labels to git commits. Don't be afraid to move labels around in the git tree.
11. WORK SCENARIO #2: BRANCH NOT MERGEABLE!
Suppose we have a branch we worked in the past days
During development we wanted to test it with other branch-development...
So ocasionally we git-merged some of those branches onto it, multiple
times :-/
Now time has come to make the pull-request and merge our work to
master :-D
Nope! Too many merge conflicts!!!
Git hates us, and Github won't give us the green merge button!
12. WORK SCENARIO #2: BRANCH NOT MERGEABLE!
$ git rebase --interactive
pick 6b2cc29 WIP: Add git talk.
# Rebase e883a09..6b2cc29 onto e883a09
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
13. THANK YOU!
These slides were made with applause
https://github.com/Granze/applause
Go check it out, it's AWESOME!