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

Introduction to Git & Github

Shreyas
January 25, 2013

Introduction to Git & Github

Slides from my lecture on tools to be used within the course in Info290 Data Mining Analysis (http://jblomo.github.com/datamining290/) at School of Information, UC Berkeley

25th Jan, 2013

Shreyas

January 25, 2013
Tweet

More Decks by Shreyas

Other Decks in Technology

Transcript

  1. WORKFLOW an opinionated discussion Grad Student, MIMS’14 Shreyas seekshreyas some

    slides adopted from and inspired by Scott Schacon’s https://github.com/schacon/git-presentations Monday, January 28, 13
  2. We’ve all been here ... Monday, January 28, 13 we

    start off a project having a fair idea of what we are going to do ...
  3. We’ve all been here ... Monday, January 28, 13 soon

    we have multiple iterations, multiple versions...
  4. We’ve all been here ... Monday, January 28, 13 and

    then we have to collaborate, share...
  5. git git is an open source, distributed version control system

    designed for speed and efficiency Monday, January 28, 13
  6. git git is an open source, distributed version control system

    designed for speed and efficiency Monday, January 28, 13
  7. git git is an open source, distributed version control system

    designed for speed and efficiency Monday, January 28, 13
  8. git git is an open source, distributed version control system

    designed for speed and efficiency (almost) everything is local Monday, January 28, 13 (almost) everything is local... branching, merging etc
  9. No Network needed for (almost) everything is local • Performing

    a diff • Viewing file history • Committing changes • Merging branches • Obtaining any other revision of a file • Switching branches Monday, January 28, 13 (almost) everything is local... branching, merging etc
  10. git git is an open source, distributed version control system

    designed for speed and efficiency http://bit.ly/git-linus-intro http://bit.ly/git-advantages More Advantages Monday, January 28, 13 initially created by Linus Torvalds, now supported by a huge open source community ... field tested with Linux Kernel
  11. .. and • No .svn directories • Independence Monday, January

    28, 13 You don’t have to go ask someone to create a branch for you, or create a repo for you or request a branch merge.. you do as you please with YOUR copy.
  12. installing git http://git-scm.com/downloads Monday, January 28, 13 We’ll be using

    the git command line interface, but feel free to choose your preferred solution GUIs, Editor Extension etc
  13. getting setup ... $ git config --global user.name “<YOUR_NAME>” $

    git config --global user.email “<YOUR_EMAIL>” or edit them in ~/.gitconfig Monday, January 28, 13
  14. lets dive in.. gitref.org/ • Creating New Repo • Committing

    • Branching/Merging • Inspection • Cloning a Repo • Updating Monday, January 28, 13
  15. lets dive in.. • Creating New Repo • Committing •

    Branching/Merging • Inspection • Cloning a Repo • Updating http://git-scm.com/docs Monday, January 28, 13
  16. Git Commands $ git init $ ls -al $ git

    init $ ls -al $ mkdir workspace $ cd workspace Initialized empty Git repository in ../workspace/.git/ drwxr-xr-x 10 Shreyas staff 340 Jan 15 17:22 .git • Creating New Repo • Committing • Branching/Merging • Inspection • Cloning a Repo • Updating Monday, January 28, 13
  17. Git Commands • Creating New Repo • Committing • Branching/Merging

    • Inspection • Cloning a Repo • Updating $ cd .git $ tree -a Monday, January 28, 13
  18. Git Commands $ git status • Creating New Repo •

    Committing • Branching/Merging • Inspection • Cloning a Repo • Updating $ cd .. $ touch testfile.md branch name staging area Monday, January 28, 13
  19. Git Commands $ git add <filename> • Creating New Repo

    • Committing • Branching/Merging • Inspection • Cloning a Repo • Updating staging area $ git status Monday, January 28, 13
  20. Git Commands $ git commit • Creating New Repo •

    Committing • Branching/Merging • Inspection • Cloning a Repo • Updating your commit msg $ git status Monday, January 28, 13 Although, I like working in small steps, here are some shortcuts git commit -m “<your msg>” [doesn’t open up the editor for msg] git commit -am “<your msg>” [adds the files tracked and uses msg on command-line]
  21. Git Commands $ git reset • Creating New Repo •

    Committing • Branching/Merging • Inspection • Cloning a Repo • Updating (undo add) changes staged changes unstaged Monday, January 28, 13
  22. Git Commands $ git reset --soft HEAD^ • Creating New

    Repo • Committing • Branching/Merging • Updating • Inspection • Cloning A Repo (undo a commit and redo) $ git reset --hard HEAD~3 Rewind the branch to get rid of last three commits http://git-scm.com/docs/git-reset http://git-scm.com/docs/git-revert.html learn more here : also refer git revert : http://git-scm.com/docs/git-stash git stash : Monday, January 28, 13
  23. Git Commands $ git rm <filename> • Creating New Repo

    • Committing • Branching/Merging • Inspection • Cloning a Repo • Updating remove a file from the repo as expected, you will need to commit the change $ git mv <filename> move/rename a file from the repo as expected, you will need to commit the change Monday, January 28, 13
  24. Git Commands $ git branch • Creating New Repo •

    Committing • Branching/Merging • Inspection • Cloning a Repo • Updating list of branches $ git branch <branchname> new branch $ git checkout <branchname> switch Monday, January 28, 13
  25. Git Commands • Creating New Repo • Committing • Branching/Merging

    • Inspection • Cloning a Repo • Updating new branch dev switch branch branch list Monday, January 28, 13
  26. Git Commands • Creating New Repo • Committing • Branching/Merging

    • Inspection • Cloning a Repo • Updating $ git merge <branchname> merge branches branch merge Monday, January 28, 13
  27. Git Commands • Creating New Repo • Committing • Branching/Merging

    • Inspection • Cloning a Repo • Updating $ git log --graph --decorate --abbrev-commit --all --pretty=oneline text-based graph :) Monday, January 28, 13
  28. Git Commands • Creating New Repo • Committing • Branching/Merging

    • Inspection • Cloning a Repo • Updating ~/.gitconfig [alias] l = log --pretty=oneline -n 20 --graph Monday, January 28, 13
  29. Git Commands • Creating New Repo • Committing • Branching/Merging

    • Inspection • Cloning a Repo • Updating $ gitk Monday, January 28, 13
  30. Working with others... • Creating New Repo • Committing •

    Branching/Merging • Inspection • Cloning a Repo • Updating github Monday, January 28, 13
  31. GitHub • Creating New Repo • Committing • Branching/Merging •

    Inspection • Cloning a Repo • Updating create an account www.github.com/edu Monday, January 28, 13
  32. GitHub • Creating New Repo • Committing • Branching/Merging •

    Inspection • Cloning a Repo • Updating add ssh key www.github.com/edu Monday, January 28, 13
  33. GitHub • Creating New Repo • Committing • Branching/Merging •

    Inspection • Cloning a Repo • Updating $ git clone <url> <name> https://github.com/jblomo/datamining290 Monday, January 28, 13 now do a demo of jim workflow
  34. GitHub • Creating New Repo • Committing • Branching/Merging •

    Inspection • Cloning a Repo • Updating Fork a repo Monday, January 28, 13 now show them a demo of creating ssh key on my ischool account
  35. GitHub • Creating New Repo • Committing • Branching/Merging •

    Inspection • Cloning a Repo • Updating $ git pull $ git push = git fetch + git merge Monday, January 28, 13
  36. GitHub • Creating New Repo • Committing • Branching/Merging •

    Inspection • Cloning a Repo • Updating GitHub Pull Request Monday, January 28, 13 show the students
  37. GitHub Ninja Features Markdown for documentation Pages for project hosting

    Gist for project hosting Service Hooks ‘do something’ on commit Monday, January 28, 13 show the students