Git 101

Git 101

B4e6cd606ce4f2122d78f259e46ea64a?s=128

Jens Segers

June 30, 2013
Tweet

Transcript

  1. Git 101 @jenssegers

  2. What is Git Code Repository Versioning Team & control

  3. Installing Git • Windows Git Bash with MinGW • OSX

    and Linux Terminal git-scm.com
  4. Git configuration $ git config --global user.name “Your Name” $

    git config --global user.email “your@email.com”
  5. Basics

  6. Creating a local repository $ git init Initialized empty Git

    repository in Hello/.git/ $ git remote add origin git@github.com:user/ Hello.git
  7. A new github repository git@github.com:user/Hello.git

  8. Checkout an existing repository $ git clone git@github.com:oSoc13/Media.git Cloning into

    'Media'... Resolving deltas: 100% (2/2), done.
  9. git add Add changes to the index $ git add

    README $ git add subfolder/* Add all files (including deleted files) $ git add -A
  10. git commit Create a new version of repository with added

    changes $ git commit -m “Adding readme” [master] created d9e1758: “Adding readme” 1 files changed, 1 insertions(+), 0 deletions(-)
  11. git push Push commits to a remote repository $ git

    push [remote] [branch] $ git push origin master Writing objects: 100% (3/3), 225 bytes, done. Total 3 (delta 0), reused 0 (delta 0)
  12. git pull Pull updates from a remote repository $ git

    pull [remote] [branch] $ git pull origin master remote: Total 3 (delta 0), reused 0 (delta 0) Updating d9e1758..c3e12cc
  13. Conflicts

  14. Conflicts A file was modified since the last pull $

    git push origin master ! [rejected] master -> master (non-fast- forward)
  15. Inspecting the conflict Update your repository $ git pull View

    conflict info $ git status Unmerged paths: both modified: README
  16. Resolving the conflict Open the conflicted file in your favorite

    editor $ nano README <<<<<<< HEAD $var = ‘foo’; ======= $var = ‘bar’; >>>>>>> a0b0bf3 ] ] local repository remote repository
  17. Push merged file $ git add README $ git commit

    -m “Merging” $ git push origin master
  18. Branching

  19. Branches

  20. Typical branches • Master The latest stable version of the

    project • Staging/Develop 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
  21. Creating a branch From the base branch $ git branch

    feature-x Switching to the new branch $ git checkout feature-x
  22. Merging a branch Switch to the base branch you want

    to merge in $ git checkout master Merge with the branch $ git merge staging
  23. Updating a branch Update a feature branch with master branch

    bug fixes $ git checkout feature-x $ git merge master
  24. Tips and tricks

  25. .gitignore A list of files that should be ignored #

    OS generated files .DS_Store .Trashes Thumbs.db # Config Config.php
  26. When all hope is lost Revert all changes to the

    last pulled version $ git reset --hard HEAD
  27. SSH keys WARNING! Only when you do not have an

    existing key pair $ ssh-keygen -t rsa -C "your@email.com" 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 a passphrase]
  28. SSH keys (2) Add your public SSH key to your

    github account (account settings) $ cat ~/.ssh/id_rsa.pub Test your settings $ ssh -T git@github.com Hi username! You've successfully authenticated, but GitHub does not provide shell access.
  29. Get git’n

  30. Learn git in 15 minutes try.github.io

  31. Git guide rogerdudler.github.io /git-guide

  32. Git cheat sheet rogerdudler.github.io /git-guide/files/ git_cheat_sheet.pdf

  33. Git branches pcottle.github.io/ learnGitBranching/

  34. Good luck