It is essential that you know how to use Git as well as GitHub. While the maintainers will be more than happy helping you make your first PR, prerequisite know-how makes it easier for everyone involved. Check this guide if you've never contributed to a project on GitHub before.
- Fork the repo from GitHub
- Clone the fork locally
- Setup a remote to the upstream (
git remote add upstream https://github.com/adeecc/DAPR.git
) - Create a new branch for the feature you are working on (
git checkout -b branch-name
) - Develop on
new-branch
- Commit your changes to the
new-branch
. (git commit -am "Descriptive Commit Message"
) - Update local dev to match upstream's dev (
git fetch upstream dev
) - Merge with local dev (
git checkout dev; git merge upstream/dev
) - Rebase
new-branch
(git checkout new-branch; git rebase dev
) - Push your branch to GitHub (
git push origin new-branch
) - Go to GitHub and submit a Pull Request to dev branch
- Try to limit the number of commits per PR to 1. If the changes are diverse enough to be put in 2 different commits, consider submitting 2 different PRs instead. (If there is no option but to submit multi commit PR's, please talk to the maintainers beforehand and read the section on multi commit PR's)
- When submitting a PR, follow the PR template and make sure to complete all the steps in the PR checklist in the PR template. (You will be able to see the template when you are submitting a new PR).
- 4 automated checks are run whenever a PR is submitted. Make sure Your PR can pass all of these checks. (Read further for details)
- Code Style Checks - 2 code style checks run for every PR, using ESLint and Prettier. It is considered good practice to run these tools locally and ensure your code meets our style guidelines before submitting a PR
- Unit Test Checks - Unit Tests are run for every submitted PR. This test also checks for code coverage. Any PR, irrespective of how important it is, will be rejected if it fails to meet the required 75% code coverage thershold
- Build Checks - The application is build and a smoke test is conducted to see if the application responds for every submitted PR.
Note: This section has concepts that may be too advanced for new Git users. It is recommended that such contributors ask for help from those more experienced.
Sometimes a PR will require or endup with more than one commit. There are two possibilities of this happening:
-
Additional granularity that each commit provides to a feature branch. An example of this is when you make big changes to the UI to follow a new set of guidelines or standard. In such a case, it may be beneficial to have separate commits for each fragment/activity that is changed.
-
New commits pushed after a review from the maintainer(s). New commits are recommended over amending existing commit(s) and force pushing since the latter would make your changes a lot harder to review.
Note that in both cases, only a single PR is required. It is the PR that will have multiple commits. In both cases, our concern is the additional commits that are added to a PR to fix problems found during code review.
Consider the case of a PR with two commits, A
and B
. After a code review, let two additional commits C
and D
be
created to fix problems found in A
and B
respectively. It might be beneficial to have both A
and B
as individual
commits after merging them into development
, instead of squashing all of them into a single commit. However, a simple
rebase of the PR would include A
, B
, C
, and D
in development
. This reduces the readability of the development
branch's history.
A possibility would be to makes the necessary changes, stage them, and then do git commit --amend
to amend B
. We can
then force push the changes. However, this is not ideal for two reasons: B
now has changes that were supposed to fix
A
, and we force pushed.
Ideally, we would like to squash C
and D
into A
and B
respectively. This can be accomplished by doing an
interactive rebase using git rebase -i HEAD~4
, reordering the commits in the todo list, and then squashing them
together. However, this process is tedious.
Git allows us to automatically squash or fixup such commits. Git does this by editing the todo list for us when we
perform an interactive rebase. Assume we want to automatically squash C
into A
, and D
into B
. This can be
accomplished as follows:
- Stage the changes to be committed. These changes will form commit
C
. - Perform
git commit --fixup ...
. Here...
is either the commit hash, or commit subject ofA
. This will create commitC
with the subject as!fixup ...
. This annotation tells Git which commitC
will fixup. - Repeat the above steps to create
D
. - Perform
git rebase -i --autosquash HEAD~4
. Use the annotations in the commit subjects, Git will generate a todo list such thatC
andD
will fixupA
andB
respectively. - Continue with the rebase and fix any merge problems you encounter.
Note that fixup
can be replaced with squash
in the above steps as well. However, the option --autosquash
for
git rebase
will remain the same for both cases.
For the sake of completeness, the difference between fixup and squash is as follows:
When
C
fixes upA
, the changes ofC
is applied toA
and the commit message ofC
is discarded and only that ofA
is used in the new commit.
When
C
is squashed withA
, the changes ofC
is applied toA
and the user is prompted to provide a new commit message for the squashed commit.
For further reading, here is the documentation for --autosquash
.