Published on

Git101 presntation for iRail Summer of code

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Git 101@jenssegers
  2. 2. In a world without Git
  3. 3. Distributed version control• Speed• Simple• Non-linear development• Fully distributed• Large projects
  4. 4. Snapshots, no ∆
  5. 5. Distributed HannesPieter JensMiet
  6. 6. Distributed and managed Hannes Pieter Jens Miet
  7. 7. Github HannesPieter Jens
  8. 8. What is Github?• Repository hosting service• Visualization of changes• Issue tracker
  9. 9. Installing Git• Windows Git Bash with MinGW• OSX and Linux Terminal
  10. 10. Git configuration$ git config --global “Your Name”$ git config --global “”
  11. 11. A new github repository
  12. 12. Creating a local repository$ mkdir Hello$ cd Hello$ git initInitialized empty Git repository in Hello/.git/$ git remote add origin
  13. 13. Git Basics
  14. 14. git addTrack files for the next snapshot$ git add README$ git add subfolder/Add all files (including deleted files)$ git add -A
  15. 15. git rmOpposite of add, untracks file$ git rm READMERecursive$ git rm -r subfolder/
  16. 16. git commitCreate a snapshot of all the added files$ git commit -m “Adding readme”[master] created d9e1758: “Adding readme”1 files changed, 1 insertions(+), 0 deletions(-)Always add an appropriate commit message!
  17. 17. git commit (2)Automatically detect changed and deleted files$ git commit -am “Adding readme”Update a previous commit$ git commit -am “GUI refactoring”$ git add new_file$ git commit --amend
  18. 18. git pushPush commit snapshots to a remote repository$ git push [remote] [branch]$ git push origin masterWriting objects: 100% (3/3), 225 bytes, done.Total 3 (delta 0), reused 0 (delta 0)
  19. 19. git pullPull updates from a remote repository$ git pull [remote] [branch]$ git pull origin masterremote: Total 3 (delta 0), reused 0 (delta 0)Updating d9e1758..c3e12cc
  20. 20. git cloneWork on an existing repository$ git clone [origin]$ git clone into ...Unpacking objects: 100%, done.
  21. 21. Conflicts
  22. 22. ConflictsA file was modified since the last pull$ git push origin master! [rejected] master -> master (non-fast-forward)
  23. 23. Inspecting the conflictUpdate your repository$ git pullView conflict info$ git statusUnmerged paths:both modified: README
  24. 24. Resolving the conflictOpen the conflicted file in your favorite editor$ nano README<<<<<<< HEADYes, this is Dog? ] local repository=======Who is Dog?>>>>>>> a0b0bf3 ] remote repository
  25. 25. Push merged file$ git add README$ git commit -m “Merging”$ git push origin master
  26. 26. Branching
  27. 27. Branches
  28. 28. Typical branches• Master The latest stable version of the project• Staging The branch where the a beta version is tested before it is merged into the master branch• Feature X A branch where a specific feature is being developed
  29. 29. Creating a branchFrom the base branch$ git branch feature-xSwitching to the new branch$ git checkout feature-x
  30. 30. Merging a branchSwitch to the base branch you want to merge in$ git checkout masterMerge with the branch$ git merge staging
  31. 31. Updating a branchUpdate a feature branch with master branch bug fixes$ git checkout feature-x$ git merge master
  32. 32. Removing a branch$ git branch -D feature-useless
  33. 33. Tips and tricks
  34. 34. .gitignoreA list of files that should be ignored# OS generated files.DS_Store.TrashesThumbs.db# ConfigConfig.php
  35. 35. When all hope is lostRevert all changes to the last pulled version$ git reset --hard HEAD
  36. 36. Credential cacheAdd cache to credentials to prevent typing username and passwordover and over again$ git config --global credential.helper cacheDefault cache is 15 minutes, to change cache use$ git config credential.helper cache --timeout=3600
  37. 37. SSH keysWARNING! Only when you do not have an existing key pair$ ssh-keygen -t rsa -C ""Generating public/private rsa key pair.Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]Enter passphrase (empty for no passphrase): [Type apassphrase]
  38. 38. SSH keys (2)Add your public SSH key to your github account (account settings)$ cat ~/.ssh/id_rsa.pubTest your settings$ ssh -T git@github.comHi username! Youve successfully authenticated, butGitHub does not provide shell access.
  39. 39. Good luck thanksTim De Pauw, Pieter Colpaert, Hannes Van De Vreken