Collaborative workflow
A suggested collaborative workflow
If you have never collaborated in a coding project using version control before, here is a suggested workflow to get started.
This is based on trunk based development
Project git structure
main(previous default name wasmaster) branch is the primary branch (i.e. the trunk)- new versions are made using
git tagonmain - all other branches on the remote are only for “backup/sync” reasons for individual developers
- follow the set branch name convention, e.g.
username/developorusername/the_work_to_do
Setup phase
If you are just joining into a project you probably need some setup to get going:
- Enter the project. If you don’t have it, then clone the repository first of course. If you do have it, get the latest changes with
git checkout maingit pull
- Create a personal branch with
git checkout -b username/develop
Work flow
The workflow is always going to be: main is the single true source, your branches are ephemeral. But you should still experiment only locally and make sure everything works before you push main to the remote. There are two ways to do this:
Long-lived up-to-date branch
Every time you start coding
- Open up project folder
- Fetch remote version of
main, this can be done withgit checkout maingit pull
- Switch to your personal branch
username/develop, if you are not already there, withgit checkout username/develop
- Make your branch up to date with
mainwithgit rebase main
- If there are conflicts, fix them (if you don’t know how, see e.g. Resolving merge conflicts after a Git rebase).
If you do not want to leave your personal branch to get the latest changes, you can do:
git fetch origingit rebase origin/main
Intense coding happens
You are finishing up a task, you have made several commits with git commit -m "meaningful message" but are not done with everything, but done with a small unit that makes sense to push to everyone else. Now you need to again make sure you are up-to-date and that you did not break anything else. Do not push changes that prevent others from doing their work.
Go trough these steps to push the code:
- Repeat the
fetch+rebaseabove, fix any possible conflicts - Make sure the parts of the code that should work, still works. This can be done with functional tests, unit tests or just by inspection.
- Make sure that you have properly updated documentation and added your important changes to the changelog.
- Fast forward
mainand push to theremote, this can be done withgit checkout maingit merge username/developgit push(orgit push origin main)
Now if you are working across multiple machines or want to back-up your work, you can do so by simply pushing your username/develop branch to the remote.
Ephemeral branches
- Open up project folder, there are no other branches, only
main git pullto get latest changesgit checkout -b username/featuremake a new branch- Intense coding happens
git checkout mainandgit pullgit merge username/featureandgit push
No branches
- Open up project folder, there are no other branches, only
main git pull- Intense coding happens
git commit -m "Good commit message" git pull --rebasegit push