The flow is triangular. Write access to the main repository on Github is restricted to certain reviewer/committers. Other team members will just have read access to this repository on github, but write access to their forks.
Setting up for this Git Workflow
- Fork the CTD master repository for the project into your own github account.
- Clone your fork onto your workstation.
- Add an additional github remote repository to local repository:
git remote add upstream <git url of the main repository>
- Do a
git pull upstream main
to synchronize with the main repository.
Git Process for Features
- git checkout main (always start your new feature branch here)
- git pull upstream main (make sure you are up to date)
- git checkout -b your-feature-name (Do not make changes to the main branch. Note: If you forget, there are ways to save your changes and to get the master branch back the way it was. For example, if you have not committed changes, you can use git stash, then create the feature branch, then do git stash apply.)
- Develop your feature.
- Add and commit your changes.
- Push your feature branch. This should be done periodically, even before you are done with your feature, so that you don’t lose your work.
- Test your feature, including any automated testing if the project has it. Make any changes necessary to make the tests pass.
- Commit and push your changes again.
- git checkout main (You need to merge in any changes that your colleagues have made in the meantime.)
- git pull upstream main
- git checkout your-feature-name
- git merge main (Now, at this point, if anyone has made changes to the same files you changed, you will need to resolve merge conflicts.)
- Resolve merge conflicts, if any, and add and commit your changes.
- Test again to make sure the merge conflict resolution did not break anything.
- Push your changes
- Do a pull request on github. The target of the pull request must be the main branch of the main repository, not your fork.
- A reviewer/committer will review your code and may request changes.
- Make any necessary changes to the your-feature-name branch and test the result. Then add, commit, and push again. It is not necessary to create a new pull request, as your changes will be added to the existing pull request.
- Once all required changes have been made, the committer will merge your code.
- Time for a new feature branch!