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

Teaching git and GitHub

Teaching git and GitHub

Slides for a 1.5-2 hour git/GitHub tutorial. In the tutorial, I walk students through different git concepts and have them practice git commands in a terminal, and then at the end I walk through interactions with remote repositories on GitHub.

Stephanie Douglas

March 30, 2016
Tweet

Other Decks in Technology

Transcript

  1. Avoid this mess Folder is “old drafts” - this doesn't

    even include submitted or revised versions!
  2. Set up git and create a repository $ git config

    --global user.name “name” $ git config --global user.email “address@gmail” $ cd code/python/ (or other folder of your choice)
  3. $ git commit -m “first commit :)” Modify a file

    (or files) Stage file(s) Commit your changes
  4. Once a file has been staged and committed, git will

    always track it Modify a file (or files) Stage file(s) Commit your changes
  5. Now commit it Modify a file (or files) Stage file(s)

    Commit your changes $ git add README $ git commit -m “describe your changes”
  6. fix_a_bug Edit one of your files and commit your changes

    master $ git add filename $ git commit -m “describe changes”
  7. Merge your changes into master and delete the branch $

    git checkout master $ git diff branch_name $ git merge branch_name $ git branch -d branch_name
  8. Merge conflict! Open the file again, look for lines like

    this: <<<<<<< HEAD the text from master ======= the text from your branch >>>>>>> branch_name
  9. Select the version you want, delete the rest. Close, add,

    and commit. <<<<<<< HEAD the text from master ======= the text from your branch >>>>>>> branch_name
  10. Clone – copy the repo to your computer GitHub (or

    other server) Remote Repository Clone Ann's Computer Local Copy
  11. Clone – copy the repo to your computer GitHub (or

    other server) origin Ann's Computer local directory
  12. Adding changes to github Open a branch, make and commit

    an edit. Then $ git push origin branch_name Now merge that branch into master, and then $ git push origin master
  13. Fetch changes from the remote repository master master origin/master $

    git fetch origin $ git branch -a $ git checkout master $ git diff origin/master
  14. Pull will fail if you have conflicting changes, and it's

    a pain to sort out Local Repository Remote Repository
  15. Fork – make your own version of someone else's repository

    GitHub (or other server) Original Repository GitHub (or other server) Fork
  16. Clone – copy a remote repository onto your computer GitHub

    (or other server) Original Repository GitHub (or other server) Fork Bob's Computer Clone of fork
  17. Remotes – links to remote repositories GitHub (or other server)

    upstream GitHub (or other server) origin Bob's Computer local repo
  18. Edit anything on local repo and the forked repo (origin)

    GitHub (or other server) upstream GitHub (or other server) origin Bob's Computer local repo
  19. Only fetch/pull from original repo (upstream); don't push GitHub (or

    other server) upstream GitHub (or other server) origin Bob's Computer local repo
  20. Add a link to my original repository GitHub (or other

    server) upstream $ git remote add upstream https://github.com/stephtdouglas/demo_fork.git OR (only if you set up ssh keys) $ git remote add upstream [email protected]:stephtdouglas/demo_fork.git $ git remote -v
  21. Pull request – ask for changes from a fork to

    be added to original repo GitHub (or other server) upstream GitHub (or other server) origin Bob's Computer local repo
  22. Add yourname.txt to your local copy of demo_fork, commit and

    push it GitHub (or other server) upstream GitHub (or other server) origin Bob's Computer local repo
  23. Open a pull request from your fork GitHub (or other

    server) upstream GitHub (or other server) origin Bob's Computer local repo
  24. Fetch and merge changes from my repository GitHub (or other

    server) upstream GitHub (or other server) origin Bob's Computer local repo $ git fetch upstream $ git diff upstream/master $ git merge upstream/master
  25. Learning more Start at GitHub's help pages - they're very

    helpful. They have a bootcamp and a cheat sheet https://help.github.com/ https://help.github.com/categories/bootcamp/ https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf How to clone, fetch, merge, and pull: https://help.github.com/articles/fetching-a-remote/
  26. Fetch and merge changes from my repository GitHub (or other

    server) upstream GitHub (or other server) origin Bob's Computer local repo $ git fetch upstream $ git diff upstream/master $ git merge upstream/master
  27. Learning more The Git docs are also useful. See their

    references pages for details and examples of commands. http://git-scm.com/docs Pretty much everything you could ever want to know about Git can be found in the Git Book: http://git-scm.com/book/en/v2 Here are different workflows for collaborating: https://www.atlassian.com/git/tutorials/comparing- workflows/centralized-workflow
  28. Which remote host? GitHub • Public repos are free •

    Link to .edu email, get 5 free private repos • Very popular, most open source projects are there BitBucket • Private repos are free • Pay for public and shared repos • Also works with mercurial (not on the same repo, though) You can use both (I do)
  29. git for publications Overleaf (formerly WriteLaTeX) has basic git integration

    in beta for unprotected projects. Sign up at https://www.overleaf.com/signup?ref=2a936e948ade Authorea also has git integration, using GitHub itself rather than their own server