Everyday effectiveness with git

Everyday effectiveness with git

Working effectively with git on a daily basis is a lot easier with a few tips on setting up your environment and making common commands faster to type. I also cover the basic kinds of code-sharing models and basic workflows for working in a collaborative environment.

D3e3f4ac37c02289f5dfed115949fc88?s=128

John Kary

April 20, 2012
Tweet

Transcript

  1. 1.

    Everyday Effectiveness with git John Kary johnkary@ gmail.com @ johnkary

    Slides available at http://johnkary.net/talks Sunday, April 22, 2012
  2. 2.

    Intermediate ? • Version control? • git status, add, commit,

    log • git Immersion http://gitimmersion.com • Branching and merging • Maybe how git works internally • Getting git by Scott Chacon http://blip.tv/scott-chacon/git-talk-4113729 Sunday, April 22, 2012
  3. 3.

    Overview • Getting over the hurdle • Setting up your

    environment • Workflow Sunday, April 22, 2012
  4. 12.

    + Automagically syncs + Cloud! + Distributed + Built-in versioning

    - Not searchable by contents - Not easy to experiment and roll-back - No diff-view between versions - No version metadata - Saved versions for only last 30 days Dropbox versioning is... Sunday, April 22, 2012
  5. 19.

    I’ve tried _____ it gets in the way of getting

    real work done Sunday, April 22, 2012
  6. 20.

    Photo: Photo by Jesse D. Garrabrant/NBAE via Getty Images The

    Truth Is... Learning git is an Investment It becomes second nature Accomplish More Work Faster Jump Higher Sunday, April 22, 2012
  7. 23.

    Installing git ~ $ brew install git ... ~ $

    which git /usr/local/bin/git Homebrew The missing package manager for OS X http://mxcl.github.com/homebrew/ Sunday, April 22, 2012
  8. 24.

    Installing git ~ $ man git-log GIT-LOG(1) Git Manual GIT-LOG(1)

    NAME git-log - Show commit logs SYNOPSIS git log [<options>] [<since>..<until>] [[--] <path>...] DESCRIPTION Shows the commit logs. The command takes options applicable to the git rev-list command to control what is shown and how, and options applicable to the git Easy man page access Sunday, April 22, 2012
  9. 25.

    Installing git ~ $ cat ~/.bash_profile source `brew --prefix git`/etc/bash_completion.d/git-completion.bash

    ~ $ source ~/.bash_profile ~ $ git sta<TAB><TAB> stage stash status ~ $ git sta Bash command auto-completion Sunday, April 22, 2012
  10. 33.

    git GUIs • Dumb-down underlying commands • Present limited command

    options • Not available on most remote servers • But there is one I recommend... Sunday, April 22, 2012
  11. 36.

    ~ $ git config --global alias.lola "log --graph --decorate >>

    --pretty=oneline --abbrev-commit --all" (master) ~/Sites/mysite $ git lola git log-one-line --all (lola) Useful when on a remote sever Sunday, April 22, 2012
  12. 38.

    PS1 ~ $ cat ~/.bash_config source `brew --prefix git`/etc/bash_completion.d/git-completion.bash export

    PS1="\[\e[0;34m\]\$(__git_ps1) \[\e[0;31m\]\w \[\e[0m\]$ " (master) ~/Sites/mysite $ git checkout 9d9bc29 Note: checking out '9d9bc29'. You are in 'detached HEAD' state. You can look around, make experimental ... ((9d9bc29...)) ~/Sites/mysite $ Sunday, April 22, 2012
  13. 39.

    • gitflow - https://github.com/nvie/gitflow • git-extras - https://github.com/visionmedia/git-extras • git-legit

    - http://www.git-legit.org • Roll your own! Command aliases Sunday, April 22, 2012
  14. 40.

    Command aliases ~ $ cat ~/.bash_config alias g="git status" alias

    go="git checkout" alias ga="git add" alias gap="git add -p" alias gb="git branch" alias gca="git commit -v --amend" Shell Sunday, April 22, 2012
  15. 41.

    Command aliases (master) ~/Sites/mysite $ g # On branch master

    nothing to commit (working directory clean) alias g="git status" (master) ~/Sites/mysite $ go 9d9bc29 Note: checking out '9d9bc29'. You are in 'detached HEAD' state. You can look around, make experimental ... ((9d9bc29...)) ~/Sites/mysite $ alias go="git checkout" Sunday, April 22, 2012
  16. 42.

    Command aliases (master) ~/Sites/mysite $ g # On branch master

    # Untracked files: # (use "git add <file>..." to include in what will be committed) # # test.php nothing added to commit but untracked files present (use "git add" to track) (master) ~/Sites/mysite $ ga test.php (master) ~/Sites/mysite $ g # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: test.php # alias ga="git add" Sunday, April 22, 2012
  17. 43.

    Command aliases (master) ~/Sites/mysite $ git commit -m "Add README"

    [master 05b8075] Add README 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 README (master) ~/Sites/mysite $ gca 1 Updated README 2 3 # Please enter the commit message for your changes. Lines starting 4 # with '#' will be ignored, and an empty message aborts the commit. 5 # On branch master 6 # Changes to be committed: 7 # (use "git reset HEAD^1 <file>..." to unstage) 8 # 9 # new file: april21-2012.zip 10 # alias gca="git commit -v --amend" Sunday, April 22, 2012
  18. 44.

    Command aliases (master) ~/Sites/mysite $ gap diff --git a/README b/README

    index 7c39865..1056e9e 100644 --- a/README +++ b/README @@ -1,3 +1,4 @@ My Cool Project +Author: John Kary -This is my first commit. +This is my second commit. Stage this hunk [y,n,q,a,d,/,s,e,?]? y alias gap="git add -p" Sunday, April 22, 2012
  19. 45.

    Command aliases Stage this hunk [y,n,q,a,d,/,s,e,?]? ? y - stage

    this hunk n - do not stage this hunk q - quit; do not stage this hunk nor any of the remaining ones a - stage this hunk and all later hunks in the file d - do not stage this hunk nor any of the later hunks in the file g - select a hunk to go to / - search for a hunk matching the given regex j - leave this hunk undecided, see next undecided hunk J - leave this hunk undecided, see next hunk k - leave this hunk undecided, see previous undecided hunk K - leave this hunk undecided, see previous hunk s - split the current hunk into smaller hunks e - manually edit the current hunk ? - print help alias gap="git add -p" Sunday, April 22, 2012
  20. 46.

    (master) ~/Sites/mysite $ gap diff --git a/README b/README index 7c39865..1056e9e

    100644 --- a/README +++ b/README @@ -1,3 +1,4 @@ My Cool Project +Author: John Kary -This is my first commit. +This is my second commit. Stage this hunk [y,n,q,a,d,/,s,e,?]? s Sunday, April 22, 2012
  21. 47.

    ... Stage this hunk [y,n,q,a,d,/,s,e,?]? s Split into 2 hunks.

    @@ -1,2 +1,3 @@ My Cool Project +Author: John Kary Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? y @@ -2,2 +3,2 @@ -This is my first commit. +This is my second commit. Stage this hunk [y,n,q,a,d,/,K,g,e,?]? n (master) ~/Sites/mysite $ git status Sunday, April 22, 2012
  22. 48.

    ... (master) ~/Sites/mysite $ git status # On branch master

    # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: README # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: README # (master) ~/Sites/mysite $ git commit -m "Add author" Sunday, April 22, 2012
  23. 49.

    ... (master) ~/Sites/mysite $ git lola * c7ccfcb (HEAD, master)

    Add README note * 9e35c29 Add author * 34501c6 Added first README Sunday, April 22, 2012
  24. 50.

    git aliases ~ $ git config --global alias.cp "cherry-pick" ~

    $ cat ~/.gitconfig [alias] b = checkout -b bd = branch -d changelog = log --oneline --reverse cp = cherry-pick lol = log --graph --decorate --pretty=oneline --abbrev-commit lola = log --graph --decorate --pretty=oneline --abbrev-commit --all difffiles = diff --name-only unstage = reset HEAD Sunday, April 22, 2012
  25. 61.

    Resources John Kary johnkary@ gmail.com @ johnkary Online git tutorial

    - http://gitimmersion.com Getting git by Scott Chacon - http://blip.tv/scott-chacon/git-talk-4113729 Optimize for developer happiness - http://codeascraft.etsy.com/2011/06/06/optimizing-for-developer-happiness/ Homebrew - http://mxcl.github.com/homebrew/ git tower - http://www.git-tower.com/ Gitbox - http://www.gitboxapp.com/ github for mac - http://mac.github.com/ GitX - http://brotherbard.com/blog/2010/03/experimental-gitx-fork/ gitflow - https://github.com/nvie/gitflow git-extras - https://github.com/visionmedia/git-extras git-legit - http://www.git-legit.org bananajour - https://github.com/toolmantim/bananajour Live-coding repo - https://github.com/johnkary/everyday-git Slides - http://johnkary.net/talks Sunday, April 22, 2012