Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Using GitHub branches and PR

Madison Jordan edited this page May 5, 2022 · 12 revisions

Project Structure

The github structure is defined to have master branches for each feature so multiple people can work on the same feature and create PR's to this master feature branch to reduce conflicts when merging code.

When feature branches (<master-feature>) are complete, that feature can be pushed to the main (default) branch.

Workflow

The general process goes as follows:

Step 1 - Develop On your local machine

  1. clone the repo

    git clone <repo>

    Skip if you have already cloned the repo

  2. switch to the master branch you'd like to work on

    git checkout <master-feature>

  3. create (checkout -b) your own personal branch from this

    git checkout -b <name>-<short_description>

    Note: You can make a PR later to merge it into the master feature branch

  4. develop as you would normally on your personal branch

    • make changes to code
    • git add . to add all files from your current directory, including those in sub-directories
    • git commit -m "commit message here"
    • git push to push to your remote branch of the same name on GitHub.

Tip: commit often to your branch and push so people can see what you are doing

Step 2 - Pull Requests (PRs) on Github

When you are reasonably sure the code for the function you are implementing is working:

  1. create a PR (on GitHub) from your branch into the master feature branch you are working on. <master-feature> <- <your-branch> at top

    Note: If you aren't sure about your code you can create a PR or draft PR and someone can easily review the changes you've made.

  2. Once you have merged your local branch into the <master-feature>, you can delete your local copy (optional) and checkout a new copy of the <master-feature> branch you want to work on.

Then repeat the above Workflow steps to (1) create a new local branch for the next function/issue you are working on and (2) create a new PR when you are done.


Updating your branch with the latest changes from the master branches

If main or the master branch has changes you'd like to merge into your local branch, you can use:

  • git pull origin main while in your branch to get the latest changes from main.
  • Or git pull origin <master-feature> if you want to pull the latest changes from the feature branch to your personal branch.

Git Command List

checkout - Switch to already created branches

git checkout main to switch to the main branch.