Skip to content

Git Workflow

Jonathan Stray edited this page Feb 9, 2018 · 17 revisions

Working on new features

This documents our command-line git workflow. Many of these actions have equivalents in your IDE. Feel free to use them, but for best results you should understand the underlying commands that the IDE is executing.

  1. Checkout out the master branch on your local machine and pull in the latest changes:
git checkout master
git pull --rebase origin master
  1. To start working on a new feature (ideally one that's captured as a user story in Pivotal), create a new branch:

git checkout -b name-of-feature

  1. Try to break the feature into relatively stand-alone chunks. These chunks may not all deliver any user-visible functionality, but they should be testable. Before each commit, run tests like this
./manage.py test
npm test
./manage.py test integrationtests

Of course this also means you need to write tests for the code you've just written. When the tests pass, you're ready to commit:

git commit -am "My changes"

  1. Push your branch to remote: git push origin name-of-feature

  2. Open a Pull Request on Github and request a code review from another team member in the Workbench Slack channel.

  3. Your reviewer will either request additional changes (go back to step 2 and repeat!) or merge your changes and delete your topic branch from remote.

  4. Delete your topic branch from your local copy: git branch -D name-of-feature

Working directly on master

For anything that will require more than one commit, use a branch as above. Otherwise:

  1. Checkout out the master branch on your local machine and pull in the latest changes:
git checkout master
git pull --rebase origin master
  1. Make sure tests pass. This is a great moment to write your tests if you haven't already. All code, front and back end, needs unit tests.
python manage.py test
npm test
./manage.py test integrationtests
  1. Check what you've changed. Use the GUI in your editor (VS Studio, PyCharm) or do

git diff

If you discover you've edited some file and you want to undo all your changes on that file (warning will destroy all your edits), you can undo all of your edits with

git checkout [filename]

  1. If it all looks good, commit. Again you can use your GUI, or to commit all changed files do

git commit -am "My changes"

  1. Push to the server

git push

  1. At this point you may discover that other people have pushed before you. If others have commits on master ahead of you, do

git pull --rebase origin master

  1. There may be conflicts. If so, edit each file with conflicts, then do

git add [conflicted file]

to tell git you are done fixing that file. When done fixing and adding all merge conflicts:

git rebase --continue

And finally:

git push origin master