GitHub Workflow
After completing the setup steps, you are ready to work on your code and data. This guide walks you through using git and github to manage your project.
Overview
- Create an issue in your repository in GitHub to plan changes with your team
- Create a new branch from the
mainbranch - Make edits to the data, code, documentation, etc
- Commit changes and push to remote
- Create Pull Request (PR) and add a Reviewer
- Implement feedback
- Merge PR into the
mainbranch - (Recommended) Remove local feature branch to keep your workspace tidy
1. Create an Issue
Creating an issue is a simple way to coordinate with others and document the decision process. The issues become a history log of a particular feature of the project allowing you and new collaborators to orient yourselves quickly.
When creating an issue:
- Use Markdown to format the text1
- Describe the problem or element to be addressed
- Describe your proposed plan to address that problem
- Discuss with collaborators2
2. Create a Branch
When creating a new branch, it's good practice to use a prefix to organize branch names. Your team should agree on a convention. Examples include:
- Type of change:
featurevsfix - Component affected:
scriptsvsdatavsdocs - Collaborator identifier (initials or username):
fridakahlovsgeorgiaokeeffe
For example, if your team chooses feature vs fix your branches might look like:
feature/add-water-temp-qc-scriptfix/empty-csv-row-added
- Open a Terminal (in RStudio or the Git-Bash terminal)
- Navigate to the project directory, if needed
- If you've made any local uncommitted changes, run
git stash - Run
git switch main - Run
git pull - Run
git switch -c [prefix]/[branch-name] - If you stashed any changes, run
git stash pop
- Open Positron
- Open the Command Palette (Ctrl + Shift + P)
- Enter "Git: Create Branch From..."
- Search for "main" and select
- Enter a name for your new branch in the form
[prefix]/[branch-name](see above)
- Click on the Git tab in the upper right pane in RStudio
- Click the dropdown next to 'New Branch' and ensure it says
main - Click on the Pull button
- Close the status pop-up
- Click New Branch
- Name the branch following
[prefix]/[branch-name]
3. Make Changes
Make your edits to the project files.
It's good practice to only make the changes outlined in the original GitHub issue. You may notice other changes that could be made, but making those changes in addition to the planned changes will create a messy commit history and make it harder for a reviewer to understand your work.
4. Save Changes
- Run
git statusto see what files have been modified - Run
git add [file_1] [dir_2]to "stage" these files - Run
git commit -m "[your commit message]"(see below) - Run
git push
If you need to "unstage" a file while keeping the changes you've made run:
git restore --staged [filename]
- Save any changes
- Expand the Version Control section from the left-hand vertical menu
- Under Changes, hover over a file and click the '+' to stage it
- Or stage all modified files at once by hovering over the Changes header and clicking the '+'
- Enter a commit message
- Click Commit
- Click Publish Branch or Sync Changes to push your changes to the remote repository
- Click the Git tab in the upper right pane in RStudio
- Click Commit
- Click Stage
- For each file listed, review your edits
- (Optional) Unselect staged files to exclude them from this commit
- On the right, enter your commit message (see below)
- Click Commit
- Click Push
File Status (untracked, unstaged, staged)
Within a git repository, files can be untracked (not monitored by git), unstaged or staged.
- Untracked files are not recorded or managed by git. You must add them with
git add [file]if you need to track them. - Unstaged files are tracked files that have been modified since the last time they were committed.
- Staged files are modified files that have been added to the group of files that will be associated with the next commit you make.
Commit Message Tips
- Summarize the changes
- e.g. "Add new qc steps for biodiversity samples (#123)"
- Link commits to GitHub issues
- e.g. by adding "
(#xxx)", pushing this commit will link the original github issue#xxx - e.g. by adding "
closes #xxx", pushing this commit will auto close that github issue.
- e.g. by adding "
5. Request Feedback (PR)
- Go to the repository in GitHub
- Click the Pull request tab
- Click New pull request
- Set the "base" to
main - Set the "compare" to your
[prefix]/[branch-name] - Scan list of commits and changes
- Click Create pull request
- Enter a title that summarizes what this PR adds
- Add any notes in the description (e.g. how you tested the changes or remaining questions you have)
- Click Create pull request (optionally create the PR as a draft)
- Along right side, add a Reviewer (an individual or a Team, like 'nearshore')
Email data@hakai.org to discuss using teams in GitHub.
6. Implement Feedback
Your reviewer should test the changes you made and offer feedback.
After you've received their review, you can go back to your original [prefix]/[branch-name] and add those changes,
then stage the files you edited, commit them, and push them.
They will automatically be appended to the open PR for that branch.
7. Merge Changes
- When ready, click Merge pull request
- (Optional) Modify the PR commit message. Close the original issue by appending "closes #xxx"
- Click Confirm merge3
- If your PR triggers any automations, you can view them under the Actions tab
Email data@hakai.org to learn more about automation options.
8. Local Cleanup - recommended
Once a branch has been merged into the main branch, we recommend deleting it from your local repository to keep your workspace tidy. Copies of these branches, unless explicitly deleted, will remain in GitHub for future reference.
- Run
git branchto list your local branches - Run
git switch main - Run
git branch -D [branch-name]to delete
- Open the Command Palette (Ctrl + Shift + P)
- Enter "Git: Checkout to..."
- Search for "main" and select
- Open the Command Palette again
- Enter "Git: Delete Branch"
- Search for and select the branch you want to delete
Deleting local branches is not possible through RStudio GUI. Use the integrated terminal.
Next Steps
Learn how to publish your data as a package.
-
See GitHub's custom Markdown for options. ↩
-
Moving relevant discussions to github issues - or at least summarizing internal threads on an issue - can help keep a public record of why changes were made. ↩
-
See merge options for different ways of integrating your changes and shaping how the git history of the main branch is written. ↩