Collaboration SOP

1. Synchronize local main with remote main branch (this step is to ensure that you have the newest update that other people might have pushed to remote repository)

git checkout main
git pull

Note: if the project contains submodules, execute following commands to fetch updates for each submodule first. This will make submodule checkout to its latest commit

git submodule update --remote --recursive

To revert back to original submodule commit, execute following commands

git submodule update --recursive


2. Whenever adding new features, bugfixs or improvements on main branch, checkout to a new branch first

git checkout -b new/module-name

Remember to push new branch to remote (Publish)

git push -u origin new/module-name


3. Before creating Pull Request(PR) and merge into main

a. First step you always checkout to main and synchronize

git checkout main
git pull

b. Next checkout back to your own branch and use interactive rebase for squash and rebase

git checkout new//module-name
git rebase -i main

During interactive rebase, you can squash redundent commits (recommended to only have only 1 commit) and remove/rephrase commits message (recommended to have only 1 message)

Important: Check these two links to understand rebase better  git rebase & Merging vs. Rebasing


Note: If there are conflicts occured, please solve conflicts together with all stakeholders first -> then execute

git rebase --continue

If anything goes wrong during solving conflicts, you can start it over by quiting the rebase process

git rebase --abort / git rebase --quit


4. Finally use force push to overwrite your own remote branch on GitHub

git push -f


5. Create (draft) pull request for code review


6. Once PR is accepted, you can checkout to main branch to synchronize

git checkout main
git pull


(Optional but Recommended) 7. Prune obsolete branches and tags

git fetch --prune --prune-tags


Other useful git resource

1. Add large size file using git lfs

git lfs track "*.yourfiletype"

2. Handy git addons on vscode:

  • i. GitLens