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

Git and GitHub: an introduction

0826c9e6449c9a08230ac6d40a3cde4d?s=47 Wendy Liu
August 07, 2013

Git and GitHub: an introduction

Internal presentation to the Network Dynamics group on using Git and GitHub.

0826c9e6449c9a08230ac6d40a3cde4d?s=128

Wendy Liu

August 07, 2013
Tweet

Transcript

  1. 1 / 41 an introduction and :

  2. 2 / 41 Distributed. SVN

  3. 3 / 41 Distributed. Git

  4. 4 / 41 Fast. Committing and pushing code: 2164+, 2259-

    git: 0.64 s SVN: 2.60 s Committing and pushing 1000, 1k images git: 1.53 s SVN: 24.70 s Viewing the log of the last 50 commits git: 0.01 s SVN: 0.38 s
  5. 5 / 41 Staging area. Index Repository git add git

    commit
  6. 6 / 41 Let's start a repository.

  7. 7 / 41 $ git clone $ git clone https://github.com/networkdynamics/zenlib

    zen
  8. 8 / 41 $ git init $ git init $

    git remote add origin https://github.com/networkdynamics/zenlib
  9. 9 / 41 $ git status # On branch master

    # # Initial commit # nothing to commit (create/copy files and use "git add" to track)
  10. 10 / 41 $ git add $ echo "Under construction"

    > README $ git add readme
  11. 11 / 41 $ git status # On branch master

    # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: README #
  12. 12 / 41 $ git diff $ git diff $

    echo "Coming soon" > README $ cat README Coming soon Staging area (index) vs working tree (filesystem)
  13. 13 / 41 $ git diff diff --git a/README b/README

    index 03b5361..3c0b0b0 100644 --- a/README +++ b/README @@ -1 +1 @@ -Under construction +Coming soon
  14. 14 / 41 $ git commit $ git commit -m

    "Add under construction message" [master (root-commit) c841ccc] Add under construction message 1 file changed, 1 insertion(+) create mode 100644 README Filesystem -> Staging area only
  15. 15 / 41 $ git show Shows the last commit

    (or any commit, or a tag, etc)
  16. 16 / 41 $ git show commit c841cccbdfdc3dbc9e5333695e492a0a2fafdfa0 Author: dellsystem

    <ilostwaldo@gmail.com> Date: Tue Aug 7 13:41:03 2012 -0400 Add under construction message diff --git a/README b/README new file mode 100644 index 0000000..03b5361 --- /dev/null +++ b/README @@ -0,0 +1 @@ +Under construction
  17. 17 / 41 $ git checkout Discard changes in working

    directory $ cat README Coming soon $ git checkout README $ cat README Under construction
  18. 18 / 41 $ git commit --amend Change the last

    commit $ echo "Under construction!" > README $ cat README Under construction! $ git add README $ git commit --amend
  19. 19 / 41 $ echo "Under construction!" > README $

    cat README Under construction! $ git add README $ git commit --amend
  20. 20 / 41 1 Add "Under construction!" message 2 3

    # Please enter the commit message for your changes. Lines starting 4 # with '#' will be ignored, and an empty message aborts the commit. 5 # On branch master 6 # 7 # Initial commit 8 # 9 # Changes to be committed: 10 # (use "git rm --cached <file>..." to unstage) 11 # 12 # new file: README 13 #
  21. 21 / 41 $ git log Show the log of

    all commit activity $ git log commit 76942d9c793578979e9cd6465f15b13e41d13d29 Author: dellsystem <ilostwaldo@gmail.com> Date: Tue Aug 7 13:41:03 2012 -0400 Add "Under construction!" message
  22. 22 / 41 $ git reset $ echo "Will be

    ready September 1." >> README $ cat README Under construction! Will be ready September 1. $ git add . $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: README #
  23. 23 / 41 $ git reset HEAD README Unstaged changes

    after reset: M README $ 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")
  24. 24 / 41 $ git add --patch Selectively committing changes

    in a file
  25. 25 / 41 def extract_feature(self, user): user_name = self.get_data(user) #

    Make it upper case and take everything before the first space first_name = user_name.upper().split()[0] value = self.data.get(first_name, 0.0) log.debug("%s: %.3f" % (first_name, value)) - return [vlaue] + return [value] ... +#================================ +# Actual features below +#================================ class NaiveWords(NaiveFeature): feature = 'words' class NaiveDigrams(NaiveFeature): } want } do not want
  26. 26 / 41 $ git add --patch features.py [...] -

    return [vlaue] + return [value] Stage this hunk [y,n,q,a,d,/,K,j,J,g,e,?]? y [...] +#================================ +# Actual features below +#================================ Stage this hunk [y,n,q,a,d,/,K,j,J,g,e,?]? q -> yes, stage this hunk -> no, and quit
  27. 27 / 41 $ git branch master (stable) bugfix awesomenewfeature

  28. 28 / 41 $ git branch Or, any other workflow.

    master develop master somebranch anotherbranch etc
  29. 29 / 41 $ git push Pushing your changes to

    a server $ git push origin master -u
  30. 30 / 41 $ git push origin master -u #

    On branch master # Your branch is ahead of 'origin/master' by 1 commit. Branch tracking
  31. 31 / 41 $ git pull Keeping your local copy

    up-to-date $ git pull
  32. 32 / 41 Merge conflicts

  33. 33 / 41 Rebasing Rewording commit messages Reordering commits Combining

    commits and more!
  34. 34 / 41 Rebasing $ git rebase -i HEAD~5 The

    last 5 commits
  35. 35 / 41 Aliasing $ git s -> status $

    git d -> diff $ git p -> add --patch
  36. 36 / 41 Multiple remote branches

  37. 37 / 41 Whitespace problems this line has trailing whitespace

  38. 38 / 41 Tagging $ git tag v1.0.0 -m "First

    gold release"
  39. 39 / 41 Bisecting

  40. 40 / 41 Git resources https://help.github.com/ Pro Git (http://git-scm.com/book) Git

    man pages (git help, git add help)
  41. 41 / 41 Github issues :: pull requests :: comparison

    view :: commit view :: blame :: history :: wiki :: markdown