Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git 102

Git 102

So you've learned the basics of Git, and you've started butting up against it. Maybe you can't quite remember all the different sub-commands and flags you use occasionally, or people have been moaning at you that your commit history is a bit messy. Ever deleted a branch accidentally and think it's gone forever? Or maybe you're using Git for editing text, and are fed up with diffs telling you a whole paragraph has changed when you've only changed a single character?

This deck gives a 100ft view of a bunch of commands and options within Git . It's not attempting to explain exactly how to use each thing, but will hopefully act as a jumping-off point for anyone who wants to either learn a bit more about Git, or become more efficient at using it.

This talk was given as part of the regular lunchtime "Tech Talks" series at Global Personals. A video of the talk is available at https://vimeo.com/92922043 (35 minutes).

Fonts:

* Franchise: http://www.fontsquirrel.com/fonts/Franchise
* Ostrich Sans: http://www.fontsquirrel.com/fonts/ostrich-sans
* Monaco (comes with OS X)

Colours:

* Text is #FFFFFF at 80% opacity (100% for highlights)
* Background colours: #141A41, #092E0E, #2B0405
* BGs are in Keynote: Advanced Image Fill > Tile, colour at 50% opacity

timblair

April 24, 2014
Tweet

More Decks by timblair

Other Decks in Programming

Transcript

  1. git-config [user] name = Tim Blair email = [email protected] [color]

    diff = auto status = auto branch = auto [alias] co = checkout ci = commit st = status -sb
  2. co = checkout ci = commit cia = commit -a

    st = status -sb br = branch Aliases
  3. merged = !git branch -r --merged origin/master \ | grep

    -v master \ | grep -v HEAD | sed 's/ origin\\///g’ ! rm-branch = !sh -c \ \"(git branch -D $1 2>/dev/null || true) && \ git push origin :$1\" - ! rm-merged = !git merged | xargs -L1 git rm-branch Aliases
  4. publish = !git push -u origin \ `git symbolic-ref --short

    HEAD` ! finish = !OLD_BRANCH="`git symbolic-ref --short HEAD`" \ && git co master && git pl \ && git br -d "$OLD_BRANCH" Aliases
  5. Custom Commands #!/bin/bash # Usage: git merge-point SHA <TARGET> !

    AIM=${2-master} ! git rev-list --ancestry-path $1..$AIM | grep -f <(git rev-list --first-parent $1..$AIM) | tail -n 1 | xargs git --no-pager show --shortstat
  6. Auto-Completion local and remote branch + tag names git subcommands

    file paths in the working directory and index common --long-options
  7. git auto-completion for your bash Auto-Completion source `brew --prefix \

    git`/etc/bash_completion.d/git-completion.bash
  8. Auto-Correction $ git pusg git: 'pusg' is not a git

    command. See 'git --help'. ! Did you mean this? push
  9. Auto-Correction $ git config --global help.autocorrect 10 ! $ git

    pusg WARNING: You called a Git command named 'pusg', which does not exist. Continuing under the assumption that you meant 'push' in 1.0 seconds automatically...
  10. Lost Commits 06770a0 HEAD@{0}: rebase finished: returning to refs/heads/master 06770a0

    HEAD@{1}: checkout: moving from master to 06770a0c b022a35 HEAD@{2}: checkout: moving from msg_id_refactor to master 912785c HEAD@{3}: commit: Refactor #message[_id] to avoid extra lookups b022a35 HEAD@{4}: checkout: moving from master to msg_id_refactor b022a35 HEAD@{5}: checkout: moving from cache-negative-lookups to master 704d342 HEAD@{6}: commit: Make conformity specs less brittle 2d9ea86 HEAD@{7}: commit: Just enabled pipelining once, not every time 024227d HEAD@{8}: commit: Clean up conformity checker 28d6a12 HEAD@{9}: commit: Break conformity checking logic out of member ed5b843 HEAD@{10}: cherry-pick: Use simpler class var references b022a35 HEAD@{11}: checkout: moving from master to cache-negative-lookups b022a35 HEAD@{12}: rebase finished: returning to refs/heads/master b022a35 HEAD@{13}: checkout: moving from master to b022a35e
  11. Revision Selection git show HEAD # By alias git show

    12a86bc38 # By revision git show v1.0.1 # By tag git show feature132 # By branch name git show 12a86bc38^ # Commit parent git show 12a86bc38~2 # Grandparent git show master@{yesterday} # Time relative git show master@{2.hours.ago} # Time relative git show :/message # Commit message
  12. Switching Branches $ git checkout - Switched to branch 'master'

    ! $ git checkout - Switched to branch 'feature' ! $ git checkout - Switched to branch 'master'
  13. git-diff $ g diff --word-diff HEAD^ ! diff --git a/README.md

    b/README.md index 2dcccf8..15d5ca7 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ I'm likely to make a [-misteak-]{+mistake+} in here somewhere.
  14. git-diff $ g diff --check ! README.md:1: trailing whitespace. +I'm

    likely to make a mistake in here somewhere.
  15. Crafting Commits Short (50 chars or less) summary of changes

    More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together. GitHub treats the first line as the title of the commit and the rest as the description. Further paragraphs come after blank lines. - Bullet points are okay, too - Typically a hyphen or asterisk is used for the bullet, preceded by a single space, with blank lines in between, but conventions vary here
  16. bf204f4 Add something I forgot f1c7e94 Add the other file

    256beed Add some text to the README Autosquash your history
  17. pick 256beed Add some text to the README pick f1c7e94

    Add the other file pick bf204f4 Add something I forgot Autosquash
  18. bf204f4 squash! Add some text to the README f1c7e94 Add

    the other file 256beed Add some text to the README Autosquash prefixed commits
  19. pick 256beed Add some text to the README squash bf204f4

    squash! Add some text to the README pick f1c7e94 Add the other file Autosquash
  20. browse your local repo using gitweb git instaweb Quick Tips

    Requires lighttp: brew install lighttpd