SlideShare a Scribd company logo
Git and Github Basics
      http://git-scm.com
Why Git?
Why Git?


Distributed Repositories
Why Git?


Distributed Repositories

Easy Merging
Why Git?


Distributed Repositories

Easy Merging

No File Locks
Starting From Scratch?
Starting From Scratch?


new_project patrick$ git init
Initialized empty Git repository in /Users/patrick/gittalk/
new_project/.git/
Existing Repository?
Existing Repository?


patrick$ git clone git@github.com:thelearninghouse/
request-forms.git <location>
Committing a change

patrick$ echo "Initial README" > README
patrick$ git add README
patrick$ git commit -m "Added README"
[master (root-commit) 5008efe] Added README
 1 file changed, 1 insertion(+)
 create mode 100644 README
What Happened?
What Happened?

patrick$ git log
commit 5008efe3eab3e746f1d54214566c6b3ed79d3656
Author: Patrick Tinsley <prtinsley@gmail.com>
Date:   Thu Oct 25 21:31:17 2012 -0400

    Added README
How Git Works
 Working Directory
               git add

     Staging
               git commit


    Repository
Work��ow

Code

Stage your changes (git add)

Review your work (git status, git diff)

Commit (locally) (git commit)

Repeat
Un-Staged Changes
Un-Staged Changes
patrick$ echo “I’m updating this again.” > README
Un-Staged Changes
patrick$ echo “I’m updating this again.” > README


patrick$ 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
#
no changes added to commit (use "git add" and/or "git commit -a")
Staged Changes
Staged Changes
patrick$ git add .
Staged Changes
patrick$ git add .


patrick$ git status
# On branch master
# Changes to be committed:
#    (use "git reset HEAD <file>..." to unstage)
#
#	 modified:    README
#
Reset
Reset
patrick$ git reset
Unstaged changes after reset:
M	 README
Reset
patrick$ git reset
Unstaged changes after reset:
M	 README


patrick$ 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
#
no changes added to commit (use "git add" and/or "git commit -a")
Hard Reset
Hard Reset
patrick$ git reset --hard HEAD
HEAD is now at e502220 Test update
Why Branch?
Why Branch?


Safely experiment with new ideas
Why Branch?


Safely experiment with new ideas

Agility
Why Branch?


Safely experiment with new ideas

Agility

Git makes branching easy
Why Branch?


Safely experiment with new ideas

Agility

Git makes branching easy

Git makes merging (usually...) very easy
Branch and Merge

c5    c4   c3   c2   c1   master


           c2   c1    new_feature
How Do We Do It?
How Do We Do It?
patrick$ git checkout -b new_feature
Switched to a new branch 'new_feature'
How Do We Do It?
patrick$ git checkout -b new_feature
Switched to a new branch 'new_feature'


patrick$ git branch
  master
* new_feature
How Do We Do It?
patrick$ git checkout -b new_feature
Switched to a new branch 'new_feature'


patrick$ git branch
  master
* new_feature


patrick$ git checkout master
Switched to branch 'master'
How Do We Do It?
patrick$ git checkout -b new_feature
Switched to a new branch 'new_feature'


patrick$ git branch
  master
* new_feature


patrick$ git checkout master
Switched to branch 'master'


patrick$ git branch -d new_feature
Deleted branch new_feature (was
5008efe).
What About Merging?
What About Merging?

patrick$ git checkout master
Switched to branch 'master'
What About Merging?

patrick$ git checkout master
Switched to branch 'master'



patrick$ git merge update_readme
Updating 01ba47f..ee04cb3
Fast-forward
 README | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Conflict!
Conflict!

patrick$ git merge update_readme
Auto-merging README
CONFLICT (content): Merge conflict in README
Automatic merge failed; fix conflicts and then commit the result.
What Happened?
What Happened?

patrick$ git status
# On branch master
# Unmerged paths:
#    (use "git add/rm <file>..." as appropriate to mark
resolution)
#
#	 both modified:       README
#
no changes added to commit (use "git add" and/or "git commit -a")
Resolve and Commit
Remote Repositories
Github.com

Another copy, much like yours

Backup

Collaborate

Distribute

Service Hooks
Working With Github
Working With Github


Update your knowledge of Github (git fetch)
Working With Github


Update your knowledge of Github (git fetch)

Update your local copy (git pull)
Working With Github


Update your knowledge of Github (git fetch)

Update your local copy (git pull)

Push your code to Github (git push)
Example
Example
example_app patrick$ git pull origin master
From github.com:prtinsley/example_app
 * branch            master     -> FETCH_HEAD
Already up-to-date.
Example
example_app patrick$ git pull origin master
From github.com:prtinsley/example_app
 * branch            master     -> FETCH_HEAD
Already up-to-date.


example_app patrick$ git push origin master
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 300 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
To git@github.com:prtinsley/first_app.git
   261f716..8b66dca master -> master
Stashing
Stashing

Cannot change branches with pending
changes

Save your work if not ready to commit

Apply pending changes to a different branch

Works like a stack
Example
Example
patrick$ 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
Example
patrick$ 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



patrick$ git stash
Saved working directory and index state WIP on master: 92a5183
Updated README
HEAD is now at 92a5183 Updated README
Example
Example
patrick$ git status
# On branch master
nothing to commit (working directory clean)
Example
patrick$ git status
# On branch master
nothing to commit (working directory clean)




patrick$ git stash apply
# 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
#
Deployments


Code pulled from repository or build archive

Code not checked in will be overwritten

Soon all production servers will be IT access
only
Resources

http://help.github.com

http://git-scm.com/book

  Definitive guide written by a Github dev

http://net.tutsplus.com/tutorials/other/easy-
version-control-with-git/

  Much more basic
GUI Clients
Tower

  http://www.git-tower.com/

SourceTree

  http://www.sourcetreeapp.com/

Github for Mac

  http://mac.github.com/
Questions?
Github
http://github.com
Context
Activity Feed
Main Repository Page
Clone URL
Branches
Commit History
Commit History
Change Sets
Excellent Help Docs



http://help.git.com
Questions?
Slides Available

More Related Content

Gittalk

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n