git session --interactive

13
git session --interactive 24 September 2014 @colmarius #Milan #Lunch-and-Learn

description

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

Transcript of git session --interactive

Page 1: git session --interactive

git session --interactive24 September 2014

@colmarius #Milan #Lunch-and-Learn

Page 2: git session --interactive

Git: ...

WHAT'S GIT?

Photo credits: http://www.slideshare.net/SeongJaePark1/deep-darkside-ofgit

Page 3: git session --interactive

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

WHAT'S GIT?

Photo credits: http://www.slideshare.net/SeongJaePark1/deep-darkside-ofgit

Page 4: git session --interactive

Using aliases for git commands

Stats: my most used commands

Useful list of git aliases

Work scenarios

AGENDA

Page 5: git session --interactive

WHAT IS IT HARD ABOUT GIT COMMANDS?

Photo credits: http://www.makerscorner.co/2014/08/productivity-hacks-git-aliases/

Page 6: git session --interactive

$ 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'

USING ALIASES FOR GIT COMMANDS

Page 7: git session --interactive

STATS: MY MOST USED GIT ALIASES

Page 8: git session --interactive

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'

USEFUL LIST OF GIT ALIASES

Page 9: git session --interactive

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... :-/

WORK SCENARIO #1: FORGOT TO BRANCH!

Page 10: git session --interactive

Tip: branches are just labels to git commits. Don't be afraid to move labels around in the git tree.

$ 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'.

WORK SCENARIO #1: FORGOT TO BRANCH!

Page 11: git session --interactive

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!

WORK SCENARIO #2: BRANCH NOT MERGEABLE!

Page 12: git session --interactive

$ 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

WORK SCENARIO #2: BRANCH NOT MERGEABLE!

Page 13: git session --interactive

These slides were made with applausehttps://github.com/Granze/applauseGo check it out, it's AWESOME!

THANK YOU!