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

Git 101

Git 101

Jens Segers

June 30, 2013
Tweet

More Decks by Jens Segers

Other Decks in Technology

Transcript

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

    repository in Hello/.git/ $ git remote add origin [email protected]:user/ Hello.git
  2. git add Add changes to the index $ git add

    README $ git add subfolder/* Add all files (including deleted files) $ git add -A
  3. 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(-)
  4. 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)
  5. 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
  6. Conflicts A file was modified since the last pull $

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

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

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

    -m “Merging” $ git push origin master
  10. 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
  11. Creating a branch From the base branch $ git branch

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

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

    bug fixes $ git checkout feature-x $ git merge master
  14. .gitignore A list of files that should be ignored #

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

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

    existing key pair $ ssh-keygen -t rsa -C "[email protected]" 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]
  17. SSH keys (2) Add your public SSH key to your

    github account (account settings) $ cat ~/.ssh/id_rsa.pub Test your settings $ ssh -T [email protected] Hi username! You've successfully authenticated, but GitHub does not provide shell access.