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

Git and GitHub: an introduction

Avatar for Wendy Liu Wendy Liu
August 07, 2013

Git and GitHub: an introduction

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

Avatar for Wendy Liu

Wendy Liu

August 07, 2013
Tweet

More Decks by Wendy Liu

Other Decks in Programming

Transcript

  1. 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
  2. 8 / 41 $ git init $ git init $

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

    # # Initial commit # nothing to commit (create/copy files and use "git add" to track)
  4. 11 / 41 $ git status # On branch master

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

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

    index 03b5361..3c0b0b0 100644 --- a/README +++ b/README @@ -1 +1 @@ -Under construction +Coming soon
  7. 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
  8. 15 / 41 $ git show Shows the last commit

    (or any commit, or a tag, etc)
  9. 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
  10. 17 / 41 $ git checkout Discard changes in working

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

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

    cat README Under construction! $ git add README $ git commit --amend
  13. 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 #
  14. 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
  15. 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 #
  16. 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")
  17. 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
  18. 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
  19. 28 / 41 $ git branch Or, any other workflow.

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

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

    On branch master # Your branch is ahead of 'origin/master' by 1 commit. Branch tracking
  22. 35 / 41 Aliasing $ git s -> status $

    git d -> diff $ git p -> add --patch
  23. 41 / 41 Github issues :: pull requests :: comparison

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