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

Git for beginners

Mike McQuaid
February 29, 2012

Git for beginners

An overview of the essentials required to use Git.
Presented at DunDDD, RIM and ConFoo.ca in 2012.

Mike McQuaid

February 29, 2012
Tweet

More Decks by Mike McQuaid

Other Decks in Programming

Transcript

  1. me

  2. $ git status # On branch master # # Initial

    commit # nothing to commit (create/copy files and use "git add" to track)
  3. $ git status # On branch master # # Initial

    commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # ReadMe.txt nothing added to commit but untracked files present (use "git add" to track)
  4. $ git status # On branch master # # Initial

    commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: ReadMe.txt #
  5. $ git commit -m "Initial commit" [master (root-commit) ba9d588] Initial

    commit 0 files changed create mode 100644 ReadMe.txt
  6. $ git status # On branch master # 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.txt # no changes added to commit (use "git add" and/or "git commit -a")
  7. $ git diff diff --git a/ReadMe.txt b/ReadMe.txt index e69de29..cd08755 100644

    --- a/ReadMe.txt +++ b/ReadMe.txt @@ -0,0 +1 @@ +Hello world!
  8. $ git status # On branch master # 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.txt # no changes added to commit (use "git add" and/or "git commit -a")
  9. $ git diff --staged diff --git a/ReadMe.txt b/ReadMe.txt index e69de29..cd08755

    100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -0,0 +1 @@ +Hello world!
  10. $ git diff master diff --git a/ReadMe.txt b/ReadMe.txt index e69de29..cd08755

    100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -0,0 +1 @@ +Hello world!
  11. $ git diff HEAD diff --git a/ReadMe.txt b/ReadMe.txt index e69de29..cd08755

    100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -0,0 +1 @@ +Hello world!
  12. $ git log commit ffc8706e41abb387993c294d7d46070a4bbd76ba Author: Your Name <[email protected]> Date:

    Mon Feb 27 21:38:38 2012 +0000 Add ReadMe commit ba9d5884d2ea8946e9bf3b6c151d61c8cd952cb1 Author: Your Name <[email protected]> Date: Mon Feb 27 21:32:41 2012 +0000 Initial commit
  13. $ git clone git://github.com/mxcl/homebrew.git Cloning into 'homebrew'... remote: Counting objects:

    58026, done. remote: Compressing objects: 100% (24408/24408), done. remote: Total 58026 (delta 37820), reused 50148 (delta 32895) Receiving objects: 100% (58026/58026), 8.69 MiB | 59 KiB/s, done. Resolving deltas: 100% (37820/37820), done.
  14. $ git log --stat 29d85 commit 29d85578e75170a6c0eaebda4d701b46f1acf446 Author: Max Howell

    <[email protected]> Date: Thu May 21 00:04:11 2009 +0100 I'll start with a rare Belgian yeast and Sussex hops README | 137 ++++++++++++++++++++++++++ 1 file changed, 137 insertions(+)
  15. $ git push Counting objects: 9, done. Delta compression using

    up to 8 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (5/5), 485 bytes, done. Total 5 (delta 4), reused 0 (delta 0) To [email protected]:mxcl/homebrew.git 4ab1f7a..753dde9 master -> master
  16. $ git fetch remote: Counting objects: 140, done. remote: Compressing

    objects: 100% (65/65), done. remote: Total 93 (delta 79), reused 42 (delta 28) Unpacking objects: 100% (93/93), done. From git://github.com/mxcl/homebrew 753dde9..3c180ba master -> origin/master
  17. $ git pull remote: Counting objects: 9, done. remote: Compressing

    objects: 100% (1/1), done. remote: Total 5 (delta 4), reused 5 (delta 4) Unpacking objects: 100% (5/5), done. From git://github.com/mxcl/homebrew 4ab1f7a..753dde9 master -> origin/master First, rewinding head to replay your work on top of it... Fast-forwarded master to 753dde9c2cf66848183f3f787f8501dbf5a7e28f.
  18. fix

  19. $ git status # On branch master # Changes to

    be committed: # (use "git reset HEAD <file>..." to unstage) # # renamed: ReadMe.txt -> ReadMe.md #
  20. $ git commit -m "Markdown ReadMe" [master a385898] Markdown ReadMe

    1 file changed, 0 insertions(+), 0 deletions(-) rename ReadMe.txt => ReadMe.md (100%)
  21. $ git status # On branch master # Changes to

    be committed: # (use "git reset HEAD <file>..." to unstage) # # deleted: ReadMe.md #
  22. $ git commit -m "Delete ReadMe" [master d84ef55] Delete ReadMe

    1 file changed, 1 deletion(-) delete mode 100644 ReadMe.md
  23. $ git revert d84ef55 [master f286fb4] Revert "Delete ReadMe" 1

    file changed, 1 insertion(+) create mode 100644 ReadMe.md
  24. $ git log HEAD~2..HEAD commit f286fb49f622b1292e8560b5c02bb8a33a115221 Author: Your Name <[email protected]>

    Date: Mon Feb 27 21:49:16 2012 +0000 Revert "Delete ReadMe" This reverts commit d84ef5556bdbd952030d19449ac6cf4af7a1b975. commit d84ef5556bdbd952030d19449ac6cf4af7a1b975 Author: Your Name <[email protected]> Date: Mon Feb 27 21:48:53 2012 +0000 Delete ReadMe
  25. $ git status # On branch master # Untracked files:

    # (use "git add <file>..." to include in what will be committed) # # ReadMe.old nothing added to commit but untracked files present (use "git add" to track)
  26. $ git diff testing diff --git a/ReadMe.md b/ReadMe.md index 717157d..cd08755

    100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,2 +1 @@ Hello world! -============
  27. $ git commit -m "Add license" [master 8e7d2b6] Add license

    1 file changed, 1 insertion(+) create mode 100644 License.md
  28. $ git diff testing diff --git a/License.md b/License.md new file

    mode 100644 index 0000000..85265b0 --- /dev/null +++ b/License.md @@ -0,0 +1 @@ +Public domain diff --git a/ReadMe.md b/ReadMe.md index 717157d..cd08755 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,2 +1 @@ Hello world! -============
  29. $ git merge testing Merge made by the 'recursive' strategy.

    ReadMe.md | 1 + 1 file changed, 1 insertion(+)
  30. $ git diff diff --git a/License.md b/License.md index 85265b0..a22a2da 100644

    --- a/License.md +++ b/License.md @@ -1 +1 @@ -Public domain +MIT
  31. $ git stash Saved working directory and index state WIP

    on master: d13413e Merge branch 'testing' HEAD is now at d13413e Merge branch 'testing'
  32. $ git stash pop # On branch master # 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: License.md # no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/stash@{0} (a3b0d391ffa40e7483e8c1194c05e628dc13f2fe)
  33. $ git diff diff --git a/License.md b/License.md index 85265b0..a22a2da 100644

    --- a/License.md +++ b/License.md @@ -1 +1 @@ -Public domain +MIT
  34. $ git commit -m "Change license" [master 836f9b7] Change license

    1 file changed, 1 insertion(+), 1 deletion(-)
  35. $ git diff diff --git a/License.md b/License.md index 85265b0..a22a2da 100644

    --- a/License.md +++ b/License.md @@ -1 +1 @@ -Public domain +MIT
  36. $ git commit -m "Change license" [master 6459532] Change license

    1 file changed, 1 insertion(+), 1 deletion(-)
  37. $ git reflog d13413e HEAD@{0}: reset: moving to HEAD^ 6459532

    HEAD@{1}: commit: Change license d13413e HEAD@{2}: reset: moving to HEAD^ 836f9b7 HEAD@{3}: commit: Change license d13413e HEAD@{4}: merge testing: Merge made by the 'recursive' strategy.
  38. $ git rebase master First, rewinding head to replay your

    work on top of it... Applying: First point
  39. $ git blame ReadMe.md f286fb49 (Your Name 2012-02-27 21:49:16 +0000

    1) Hello world! 85200e28 (Your Name 2012-02-28 14:30:47 +0000 2) ============ 18a2fded (Your Name 2012-02-28 12:03:40 -0500 3) * First point