Share
Embed
Get a Jumpstart on Collaboration and Code Review in GitHub- devICT Hacktoberfest
KatherineMichel
September 28, 2017
Transcript
101 slides
-
Get a Jumpstart on Collaboration and Code Review in GitHub
By Katherine “Kati” Michel -
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 -
Goal I want to teach you a process that will
get you started collaborating and doing code review as quickly as possible -
DjangoCon US Website as an Example Project DjangoCon US Website
Homepage DjangoCon US Website Repo -
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 -
What are Git and GitHub? GitHub is a website built
on the version control software Git. GitHub Website Git Command Line -
Social Network Make a User Profile Follow People Follow Activity
in Newsfeed Find Interesting Projects -
Repositories GitHub users work on code together DjangoCon US Organization
Account Repo List DjangoCon US Website Repo -
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 -
Working on a File in GitHub File on GitHub (README)
Editing File Click pencil icon Edit Commit Info Save -
How to Create a Branch File on GitHub (README) Editing
File Click pencil icon Edit Commit Info Save -
How to Create a Branch New branch and name File
on GitHub (README) Editing File -
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 -
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 -
Write Permission When a user has write permission to a
repo, it means they can make changes directly inside of the repo -
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 -
Write Permission and Collaboration Examples Shared Repository DjangoCon US Website
Repo Write Permission: Maintainers -
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 -
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 -
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 -
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 -
DjangoCon US Website Repo remote origin Fork and Pull Model
My Fork Fork Clone Local Development Environment -
DjangoCon US Website Repo remote origin Fork and Pull Model
My Fork Fork Clone Push changes, including branches Local Development Environment -
DjangoCon US Website Repo remote origin Fork and Pull Model
My Fork Fork Submit Pull Request Clone Push changes, including branches Local Development Environment -
DjangoCon US Website Repo remote origin Shared Repository Clone Local
Development Environment -
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 -
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 -
Adding and Committing $ git add . $ git commit
-m “Creating branch and updating” -
Submit a Pull Request DjangoCon US Website Repo Creating a
New Pull Request -
Submit a Pull Request DjangoCon US Website Repo Creating a
New Pull Request Title and Description Look over changes Create Choose branches -
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 -
Pull Request Review Process Look over changes Title and Description
Merge button Command line instructions -
Pull Request Review Options Do no run code locally Run
code locally Click merge Make change in browser then click merge -
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 -
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 -
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> -
Merge Pull Request Locally and Push to Master Branch $
git checkout master $ git merge --no-ff <branch-name> $ git push origin master -
Tidy Up $ git branch -d <branch-name> $ git branch
-D <branch-name> $ git push <remote-name> :<branch-name> -
Advanced Topics • Rebase • Interactive rebase • Squashing •
Merge Conflicts • Aliases • Fetch individual pull request branches -
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 -
Common Adding and Committing Commands $ git add . $
git commit -m "Your note" $ git commit -am "Your note" -
Manual Updates • When you make a change somewhere, the
code does not automatically update elsewhere -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
Another Workflow Master Branch Live Production Site Pull Requests Staging
Site Develop Branch -
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 -
Common Branch Commands $ git checkout <branch-name> $ git checkout
-b <branch-name> $ git checkout -b <branch-name> <branching-off> -
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 -
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 -
Productivity Tips • Password caching • Closing issues via commit
messages • Saved replies • Link to specific line numbers on GitHub -
Triaging Triaging Labels • help wanted • first-timer • good
first contribution • mentor available • up-for-grabs -
Getting Help • Help via Git, GitHub Help and Guides
• Help via command line (exit by typing “q”) • Help via GitHub Keyboard Shortcuts (type "?") -
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 -
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. -
Thank You! Katherine “Kati” Michel Twitter handle: @KatiMichel GitHub username:
KatherineMichel Useful Resources: https://git.io/v5WMG