knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Introduction

This article will give you an overview of how the {admiral} project is utilizing the version-control software git and the website GitHub while working with RStudio. We will go over the primary branches that house the source code for the {admiral} project as well as how we use Feature branches to address Issues. Issues can range from bugs to enhancement that have been identified or requested by developers, users or testers. Finally, we provide the bare minimum of git commands needed to get up and running. Please refer to the Resource section for more in-depth guidance on using git and GitHub.

Branches

Working with Feature Branches

Feature Branches are where most developers will work when addressing Issues.

Implementing an Issue

Each feature branch must be related to an issue.

Name:
The name of the branch must be prefixed with the issue number and be meaningful, e.g. issue #94 "Program function to derive LSTALVDT", the Branch name would be: 94_lstalvdt.

Create a New Feature Branch from the Terminal (from devel)

Create a New Feature Branch from GitHub (from devel)

You can also create a feature branch in GitHub.

    knitr::include_graphics("github_feature_branch.png", dpi = 144)

Commits from the Terminal in RStudio

To start the commit process, you will need to tell git to move your changes to the staging area. Use git add <your_file> to move all changes of <your_file> in the staging area to wait for the next commit. You can use git add . to move all files you have worked on to the staging area. Next you can commit, which takes a snapshot of your staged changes. When committing, prefix the message with the issue number and add a meaningful message git commit –m '#94 last alive date implementation'.

Lastly, you should push your changes up to GitHub using git push origin <branch name>

Commits from the Git Tab in RStudio

You can also make use of the Git Tab within RStudio to commit your changes. A benefit of using this Tab is being able to see your changes to the file with red and green highlighting. Just like in the terminal, start the message with the issue number and add a meaningful and succinct sentence. Hit the Commit button and then Push up to GitHub.

    knitr::include_graphics("github_committ.png", dpi = 144)

NOTE: Placing the issue number in your commit message allows new developers to quickly find discussion surrounding your issue. When pushed to GitHub the issue number will hyperlink to the issue tracker. A powerful tool for discussion.

Pull request

We recommend a thorough read through of the articles, Pull Request Review Guidance and the Programming Strategy for in-depth discussions on a doing a proper Pull Request. Pull Request authors will benefit from shorter review times by closely following the guidance provided in those two articles. Below we discuss some simple git commands in the terminal and on GitHub for doing a Pull Request. We recommend doing the Pull Request in GitHub only and not through the terminal.

Once all changes are committed, push the updated branch to GitHub:
git push -u origin <branch_name>

In GitHub, under Pull requests, the user will either have a "Compare and pull request" button and/or a "Create Pull Request". The first button will be created for you if GitHub detects recent changes you have made. The branch to merge with must be the devel branch (base = devel) and the compare branch is the new branch to merge - as shown in the below picture. Please pay close attention to the branch you are merging into!

The issue must be linked to the pull request in the "Linked issues" field of the Pull Request.

    knitr::include_graphics("github_linked_issues.png", dpi = 144)

Once you have completed the Pull Request you will see all committed changes are then available for the reviewer. A reviewer must be specified in the Pull Request. It is recommended to write a brief summary to your reviewers so they can quickly come up to speed on your Pull Request. Pictures are nice too, which are easy to do in GitHub! Use any Screen Capture software and Copy and Paste into your summary.

    knitr::include_graphics("github_create_pr.png", dpi = 144)

Reviewing/Closing an Issue

Once the review is completed, the reviewer will merge the Pull Request and the feature branch will automatically be deleted.

After merging the Pull Request the corresponding issue must be moved to the "Sprint Done" column on the "admiral scrum board" by the developer. The issue must not be closed. It will be closed automatically once the devel branch is merged into the main branch.

    knitr::include_graphics("github_sprint_done.png", dpi = 144)

Solving Merge Conflicts in the Terminal on RStudio

Merge conflict is a situation where git cannot decide which changes to apply since there were multiple updates in the same part of a file. This typically happens when multiple people update the same part of code. Those conflicts always need to be handled manually (as some further code updates may be required):

git checkout devel
git pull
git checkout <feature_branch>  
git merge devel

This provides a list of all files with conflicts In the file with conflicts the conflicting sections are marked with <<<<<<<, =======, and >>>>>>>. The code between these markers must be updated and the markers be removed. Source files need to be updated manually. Generated files like NAMESPACE or the generated documentation files should not be updated manually but recreated after the source files were updated.

To make the changes available call:

git add <file with conflict> 
git commit -m "<insert_message>"
git push

Solving Merge Conflicts in GitHub

For simple merge conflicts, developers can make use of the GitHub interface to solve them. GitHub will show the number of conflicts between the two branches. In the below image, Github has found 3 conflicts, but we only display the first one. Just like in the terminal, GitHub will make use of the <<<<<<<, =======, and >>>>>>> to highlight the conflicting sections. You will need to make the decision on whether to keep the code from the base or the feature branch. Once you have decided, go into the code and remove the section you no longer wish to keep. Be sure to remove the <<<<<<<, =======, and >>>>>>> as well! Once you work through the conflicts you will mark as Resolved and Commit your changes. It is recommended to pull your branch back down to RStudio to make sure no untoward effects have happen to your branch.

    knitr::include_graphics("github_conflicts.png", dpi = 144)

Useful git Commands

Using code from unmerged branches

Resources on using git, GitHub and RStudio {#github_resources}



epijim/admiral documentation built on Feb. 13, 2022, 12:15 a.m.