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

Get a Jumpstart on Collaboration and Code Review in GitHub- devICT Hacktoberfest

Get a Jumpstart on Collaboration and Code Review in GitHub- devICT Hacktoberfest

KatherineMichel

September 28, 2017
Tweet

More Decks by KatherineMichel

Other Decks in Technology

Transcript

  1. About Me • DjangoCon US Website Chair • DEFNA (Django

    Events Foundation North America) Board Member • DjangoCon Europe Website Committee Member • Project Manager • Web Designer and Developer Twitter: @KatiMichel GitHub: KatherineMichel
  2. Goal I want to teach you a process that will

    get you started collaborating and doing code review as quickly as possible
  3. Prerequisites for Getting Started • Create a free GitHub account

    online • Install Git on your computer • Find and open your command line (a.k.a. terminal) on your computer • Be able to navigate via command line (See Bash commands) • You might also want to have a code/text editor of your choice installed
  4. What are Git and GitHub? GitHub is a website built

    on the version control software Git. GitHub Website Git Command Line
  5. Collaboration and Code Review Best Practice Workflow You need to

    switch between multiple tasks: • Keep codebase up-to-date • Create one or more features • Do code review
  6. Working on a File in GitHub File on GitHub (README)

    Editing File Click pencil icon Edit Commit Info Save
  7. How to Create a Branch File on GitHub (README) Editing

    File Click pencil icon Edit Commit Info Save
  8. How to Create a Branch New branch and name File

    on GitHub (README) Editing File
  9. Overview • Determine which collaboration approach to use • Clone

    a repo into our local development environment, create a feature branch, make a change, push the branch to the GitHub repo, and submit a pull request • Review the two different types of pull request branches as a maintainer • Practical commands and additional workflow info • Recommendations
  10. The Two Collaborative Development Models • “Shared Repository” Model •

    “Fork and Pull” Model The two different models typically correspond to the two different account types and which model you use depends on whether you have write permission to the repo
  11. Write Permission When a user has write permission to a

    repo, it means they can make changes directly inside of the repo
  12. Examples of What Write Permission Will Allow You to Do

    • Edit files • Push branches directly to the repo (instead of via fork) • Merge and close pull requests
  13. Fork Submit Pull Request Fork and Pull Fork Write Permission:

    User Write Permission and Collaboration Examples Shared Repository DjangoCon US Website Repo Write Permission: Maintainers
  14. How to Fork a Repo Click the “Fork” button Click

    pencil icon to try to edit a file you don’t have write permission to DjangoCon US Website Repo
  15. How to Fork a Repo Click the “Fork” button DjangoCon

    US Website Repo GitHub will notify you that the repo is being forked Click pencil icon to try to edit a file you don’t have write permission to
  16. Section 2 • Determine which collaboration approach to use •

    Clone a repo into our local development environment, create a feature branch, make a change, push the branch to the GitHub repo, and submit a pull request
  17. DjangoCon US Website Repo remote origin Fork and Pull Model

    My Fork Fork Clone Local Development Environment
  18. DjangoCon US Website Repo remote origin Fork and Pull Model

    My Fork Fork Clone Push changes, including branches Local Development Environment
  19. DjangoCon US Website Repo remote origin Fork and Pull Model

    My Fork Fork Submit Pull Request Clone Push changes, including branches Local Development Environment
  20. DjangoCon US Website Repo Push branches, submit pull requests remote

    origin Can push or pull because of write permission, No fork needed Shared Repository Clone Local Development Environment
  21. Bash Commands Go to the home directory $ cd Change

    directory $ cd <directory-name> Move back a directory $ cd .. List the folders and files in a directory $ ls
  22. Adding and Committing $ git add . $ git commit

    -m “Creating branch and updating”
  23. Submit a Pull Request DjangoCon US Website Repo Creating a

    New Pull Request Title and Description Look over changes Create Choose branches
  24. Section 3 • Determine which collaboration approach to use •

    Clone a repo into our local development environment, create a feature branch, make a change, push the branch to the GitHub repo, and submit a pull request • Review the two different types of pull request branches as a maintainer
  25. Pull Request Review Options Do no run code locally Run

    code locally Click merge Make change in browser then click merge
  26. Pull Request Review Options Do no run code locally Run

    code locally Click merge Make change in browser then click merge No change needed, go back to browser and click merge Ask pull request author to make change You push change to pull request, then click merge You update and merge locally, push to GitHub
  27. Pull Request Branches DjangoCon US Website Repo Fork Write permission

    granted to pull request as maintainers local branches remote origin updates pull request branch git fetch origin <remote>/<branch> .git folder git pull <url> <branch> pull request branch
  28. Pull Request Review Shared Repo Branch Forked Repo Branch $

    git fetch origin $ git checkout -b <branch-name> origin/<branch-name> $ git merge master $ git push origin <branch-name> $ git checkout -b <branch-name> master $ git pull https://github.com/<user-name>/<repo-name> <branch-name> $ git push https://github.com/<user-name>/<repo-name> <branch-name>
  29. Merge Pull Request Locally and Push to Master Branch $

    git checkout master $ git merge --no-ff <branch-name> $ git push origin master
  30. Tidy Up $ git branch -d <branch-name> $ git branch

    -D <branch-name> $ git push <remote-name> :<branch-name>
  31. Advanced Topics • Rebase • Interactive rebase • Squashing •

    Merge Conflicts • Aliases • Fetch individual pull request branches
  32. Section 4 • Determine which collaboration approach to use •

    Clone a repo into our local development environment, create a feature branch, make a change, push the branch to the GitHub repo, and submit a pull request • Review the two different types of pull request branches as a maintainer • Practical commands and additional workflow info
  33. Common Adding and Committing Commands $ git add . $

    git commit -m "Your note" $ git commit -am "Your note"
  34. Manual Updates • When you make a change somewhere, the

    code does not automatically update elsewhere
  35. Fetching Versus Pulling Any Repo Local branches <remote> can be

    name or URL Remote branches git fetch <remote> git pull= git fetch + git merge git pull git checkout <branch> git pull <remote> <branch> git push <remote> <branch> git fetch git merge git checkout <branch> git merge <remote>/<branch> git push <remote> <branch> .git folder Need write permission to push
  36. DjangoCon US Website Repo remote origin Syncing With a Fork

    My Fork push updates Local Development Environment Add remote upstream fetch/merge or pull updates
  37. DjangoCon US Website Repo fetch/merge or pull updates remote origin

    No fork needed because of write permission Syncing with a Shared Local Development Environment push updates
  38. Adding a Remote Upstream $ git remote add <remote-name> <remote-url>

    $ git remote -v origin https://github.com/your-username/your-fork (fetch) origin https://github.com/your-username/your-fork (push) upstream https://github.com/upstream-username/original-repository (fetch) upstream https://github.com/upstream-username/original-repository (push) $ git remote add upstream https://github.com/upstream-username/original-repository
  39. Syncing Commands $ git checkout <branch-name> $ git pull <remote-name>

    <branch-name> $ git push <remote-name> <branch-name> $ git pull https://github.com/<user-name>/<repo-name> <branch-name> $ git push https://github.com/<user-name>/<repo-name> <branch-name> $ git fetch <remote-name> $ git checkout <branch-name> $ git merge <remote-name>/<branch-name> Pushing and pulling Fetching and Merging
  40. Common Syncing Scenarios $ git fetch origin $ git checkout

    master $ git merge origin/master $ git fetch upstream $ git checkout master $ git merge upstream/master $ git push origin master Updating a shared repo clone Updating a forked repo clone
  41. Common Syncing Scenarios, Cont’d $ git checkout master $ git

    pull origin master $ git push origin master $ git checkout example-branch $ git merge master or <remote-name>/master Updating a feature branch Updating the master branch by pulling/pushing
  42. Learn More About Workflow • GitHub Flow (basically, what we’ve

    been using) • A Successful Git Branching Model (more advanced) • A Successful Git Branching Model Considered Harmful (alternative view) • SemVer • See also: Atlassian and GitLab docs
  43. Common Branch Commands $ git checkout <branch-name> $ git checkout

    -b <branch-name> $ git checkout -b <branch-name> <branching-off>
  44. Section 5 • Determine which collaboration approach to use •

    Clone a repo into our local development environment, create a feature branch, make a change, push the branch to the GitHub repo, and submit a pull request • Review the two different types of pull request branches as a maintainer • Practical commands and additional workflow info • Recommendations
  45. Additional Safety Considerations • Back up the repo • Enable

    required reviews of pull requests • Use status checks (external) • Revert pull requests, if needed • Worst case scenario: How to recover deleted branch • Sensitive data warning
  46. Productivity Tips • Password caching • Closing issues via commit

    messages • Saved replies • Link to specific line numbers on GitHub
  47. Triaging Triaging Labels • help wanted • first-timer • good

    first contribution • mentor available • up-for-grabs
  48. Getting Help • Help via Git, GitHub Help and Guides

    • Help via command line (exit by typing “q”) • Help via GitHub Keyboard Shortcuts (type "?")
  49. Debunking Myths • Myth: The repos look perfect. • Myth:

    The people working on GitHub projects must all be experts; I probably don’t fit in here. • Myth: GitHub users seem to know exactly what to do • Myth: This is all about code • Myth: I don’t want to break something
  50. Go For It! Contribute to the DjangoCon US website next

    year! We have a diverse group of contributors of all skill levels and we are always looking for more contributors. Let us know if you are interested.
  51. Thank You! Katherine “Kati” Michel Twitter handle: @KatiMichel GitHub username:

    KatherineMichel Useful Resources: https://git.io/v5WMG