- Adopt and practice a Pull Request Workflow to:
- Collaborate with yourself (on independent projects)
- Collaborate with people you don't know (on open source projects)
- Collaborate with teammates (on team projects)
Follow the instructions in each of the exercises below, to practice collaboration for three different use cases. For the second and third use case, we'll be using specific repos and wanting to make specific changes to those repos.
This is the process we will follow to add or revise the functionality of our own existing repos:
- Choose one of your existing GitHub repos, or create a new one (i.e. the "origin" repo).
- Clone the repo locally if you haven't already done so. Ensure your local main branch is up-to-date with the origin main branch.
- Checkout a new local feature branch called something like "new-feature-123".
- Modify some part of the codebase (for this exericse, any trivial change will do), save your work, and make a commit on the local feature branch.
- Push the local feature branch revisions to the origin repo.
- Create a Pull Request to compare the feature branch changes against the main branch.
- In the Pull Request, review the changes and optionally make some comments.
- When you are satisfied with the changes, merge the Pull Request via the GitHub interface.
To repeat the process (after changes have been merged):
- Checkout the main branch, and pull the most recent changes from the origin main branch.
- Then repeat steps 3-8 above.
This is the process we will follow to add or revise the functionality of repos we don't own or have write access to:
- Choose a repo owned by someone else, that you don't have direct write access to (i.e. the "upstream" repo). Like this example open source repo.
- Fork the upstream repo to create a copy under your own control (i.e. the "origin" repo).
- Clone the origin repo locally. Ensure your local main branch is up-to-date with the upstream and origin main branches.
- Checkout a new local feature branch called something like "new-feature-123".
- Modify some part of the codebase (for this exercise, the change we'll make is to add a new file in the app directory called "[USERNAME]_script.py", with some example print statements inside it), then save your work, and make a commit on the local feature branch.
- Push the local feature branch revisions to the origin repo.
- Create a Pull Request to compare the origin feature branch changes against the upstream main branch.
- Wait until a maintainer of the upstream repo takes further action - eventually hopefully merging your code into the upstream main branch.
To repeat the process (after changes have been merged):
- After the changes have been merged to the upstream repo, visit your origin repo on GitHub and click "Fetch Upstream" to update your origin main branch.
- From GitHub Desktop, checkout the main branch, and pull the most recent changes from the upstream main branch.
- Then push those changes to the origin main branch, to ensure it is up-to-date with the upstream main branch.
- Then repeat steps 4-8 above.
For team projects, it is possible for each collaborator to fork the original repo and use the "Open Source Projects" approach described above to contribute.
Otherwise, for teams who want everyone to have write access to the same shared repo, see the process below:
- Create a new repo under your own control and invite other members as collaborators, or join an existing repo that someone else has invited you to collaborate on. For example you could request access to this example shared repo.
- Clone the repo locally if you haven't already done so. Ensure your local main branch is up-to-date with the origin main branch.
- Checkout a new local feature branch called something like "[USERNAME]-new-feature-123". We include the username in the branch name so our branch names will stay unique and not conflict with other people's branches.
- Modify some part of the codebase (for this exercise, the change we'll make is to add a new file in the app directory called "[USERNAME]_script.py", with some example print statements inside it), then save your work, and make a commit on the local feature branch.
- Push the local feature branch revisions to the origin repo.
- Create a Pull Request to compare the feature branch changes against the main branch.
- Ask a repo collaborator to conduct a Code Review on your Pull Request.
- Wait until a collaborator takes further action - reviewing your code and hopefully eventually approving your changes. After approving the changes, either you or a collaborator can merge the code via the GitHub interface.
To repeat the process (after changes have been merged):
- After the changes have been merged to the upstream repo, visit your origin repo on GitHub and click "Fetch Upstream" to update your origin main branch.
- From GitHub Desktop, checkout the main branch, and pull the most recent changes from the origin main branch.
- Then repeat steps 3-8 above.