Up until now you have worked on a single (default) git branch, 'main'. This was fine when you were working independently, but now we are working as a team we need to isolate our development work until we consider it 'ready for review', so as not to affect other team members using the repository.
Each repository has one default branch and can have multiple other branches. You can merge
a branch into another branch using a Pull Request
.
Best practice is to create a new branch for each issue you work on. You should include the issue number in the name of the branch as well as a short descriptive name, for example '3-data-model'.
New branches can be created either via the GitHub UI (recommended) or via the command line using the git checkout -b
command.
To work on a specific branch you need to 'checkout' that branch:
git checkout nameOfBranch
To confirm which branch you are working on, run:
git branch
This will show a * against the branch you have checked out.
You can now safely commit & push to your branch without affecting anyone else in your repository. Do ensure you push regularly just in case your local machine crashes!
If you execute git push
without any arguments, it will push the changes to the currently checked out branch (which is typically what you want).
When you have finished working on your branch, make a 'Pull Request' and assign it to a reviewer (someone else from your team must look through your code before it is merged). Move the associated 'Issue' card into the 'In review' column. You can now start work on another Issue.
If you are asked to be a reviewer you should review the code carefully, check that it is well documented and has unit tests. Ask if you have any questions. When you are happy you can 'merge' the Pull Request and select to 'delete' the branch - merging will apply the code changes to the 'main' branch. No-one should ever merge their own code into main.
git checkout nameOfYourBranch
git branch
and ensure you see a * next to your branch namegit checkout main
and run git pull
to get the latest changes. Delete your old branch using git branch -D nameOfYourMergedBranch
.