Skip to content

Branch Workflow

George from Seattle edited this page Sep 17, 2020 · 2 revisions

Branching Workflow

Creating a new branch:

  • In the terminal, enter git checkout -b your-branch-name. This will create a new branch called your-branch-name. You can verify this by running git branch.
  • Add & commit your changes as normal inside of your branch.
  • Whenever anyone merges changes with origin master, your branch will now be behind master! You will need to go through the following sequence locally before creating your pull request on GitHub:

git checkout master

git pull

git checkout your-branch-name

git merge master

(Another option is to use the console command git pull origin master from within your-branch-name. This pulls from master and attempts to merge directly on your branch.)

Linting:

While Travis CI will run a build test on your code after you submit a pull request, you can also run your own linting test before pushing by using the following command:

npm test

This will run the ESLint test on your code base and allow you to fix any errors before doing your final commit & push to the remote repository.

Creating a Pull Request:

  • To push your branch to github, use the console command git push origin your-branch-name.
  • On the main repo page on GitHub, click "Compare & Pull Request".
  • On the next page, add a description of the work that was done and click the "Pull Request" button.
  • This should create a pull request for your branch, viewable under the Pull Requests tab on the repo.

Reviewing Pull Requests:

  • Each reviewer should carefully look at the code to make sure all changes are understood & will not break the website. It is far easier to change something on a branch than after it has been pushed to master!

  • To view commits from a pull request locally, use the following console commands:

    git fetch
    
    git checkout -b your-branch-name origin/your-branch-name
    
  • After reviewing / testing the code, return to the master branch by typing git checkout master in the console.

  • Go back to the pull requests tab on GitHub and select the request you were reviewing. If you click the "Files Changed" tab, you should see all changes made.

  • If there are any changes you would like made, you can click the line number to leave a comment the PR author will see and should address before approval. Otherwise click "Review changes" and approve the PR.

  • Click the "Merge pull request" button to add the branch's changes into master. Once complete you can delete the feature branch from your machine by running the following in your terminal: git branch -D your-branch-name

  • Remember to use git pull on your master branch to update it!

Notes on Pull Requests:

Have 1-2 reviewers for each PR pull request.

Watch out for multiple people working on the same files. So make different script files. Ideally, each person working on their own file. Always update your branch with master after a PR is merged.

Each person has to do this. & Accept changes made by others. If changes from master are not accepted, and later that person does a PR with my-branch, then it can break master.

Look at files changed.

Get the git history extension.

Don't forget to periodically declutter the repo by deleting old & no-longer-necessary (already-merged-with-master) branches. See detailed instructions here.