Pull requests with Github
github
tutorial
workflow
When people collaboratively develop software (R packages) and use Github as a repository, colleagues can review software parts before they are included in an updated package version.
Recommended Workflow
- Pull all changes from the relevant branch. Normally, this will be the branch
main
, but it might also happen that you want to extend on another branch. Create
andcheckout
(change onto the branch) on a new branch. By default, this will create a new branch from main, but you can also create a new branch from any other branch, if you want to extend on it.- Make changes in your local repository.
Commit
them as often as possible. The more you commit, the more of you work gets saved regulary.- If you want to upload your changes,
Push
. - Repeat 3 - 5 until you are done.
Initiating a review
Once you are content with your changes and you want to finalize them, you can initiate a review:
- Change to the the Github page of the package (for example, eatTools repository) and start the
pull request
via “Compare & pull request”. This will open a new page, where you can customize your pull request. - Choose your favorite reviewer under “Reviewer”. You can ask multiple people.
- Enter a comment for the request, specifying what you want the reviewer(s) to look for especially.
- Click on “create pull request” to start the request.
Review Process
- Now the review process begins: The person that takes over the review assigns herself on the right side of the pull request page. Keep in mind our Code Conventions.
- The reviewer can request changes, either general ones or specific ones by adding comments to specific lines of code.
- In the end, the reviewer delivers their final verdict:
approve
orrequest changes
. - Now it’s the authors turn again: the author has to address the comments of the reviewer and make requested changes, or discuss why certain requested changes should not be made.
- The changes can either be made on the branch the pull request was initiated on or on a new branch that branches out from this branch. If many changes are made, it might be easier to work on a seperate branch and initiate a new pull request to merge it onto the parent branch (where the first pull request was made) to make clearer which new changes have been made.
- Reiterate until the author and reviewer have reached an agreement.
- If both are satisfied. On the GitHub Pull-request page, select “merge pull request into main” (or any other branch you want to and can merge on) at the bottom.
- Finally, the review branch can be deleted. Choose “delete” on the Github homepage. Then delete the local branch (i.e. in GitKraken) in the same way if necessary
Please note
As long as the master/main branch and the new branch are not merged again, there are two “parallel” branches. The background to this is that - as long as developers are working in the new branch - users can always download the latest working version (i.e. the master branch) of the package. As a developer, you always have to check and be conscious about on which branch you are currently working on.
Git-Workflow im Terminal (NH)
- Gegebenenfalls: Auf den mainbranch wechseln:
git checkout main
- Verifizieren, dass man auf dem richtigen branch ist:
git status
- Onlinebranch lokal herunterladen:
git pull
- Gegebenenfalls: Neuen branch “branch_2” erstellen, und direkt darauf wechseln:
git checkout -b branch_2
- (Alle) Änderungen stagen:
git add .
- Gestagte Änderungen commiten (mit aussagekräftiger Commitmessage):
git commit -m "implemented new function"
- Commits hochladen:
git push
Footnotes
Image by Roman Synkevych on Unsplash.↩︎