The following describes two different workflows for contributing software to an open-source repository on GitHub under the spacetelescope
organization (hereby referred to as the "spacetelescope
repository"). One model involves creating branches off of the spacetelescope
repository directly (hereby referred to as the "branching workflow"), while the other involves forking the spacetelescope
repository and developing changes on personal branches of the fork (hereby referred to as the "forking workflow"). Regardless of which model is chosen, software changes ultimately get incorporated into the spacetelescope
repository through pull requests. Below, we provide some pros/cons for each workflow. We encourage developers to chose a workflow that is most appropriate for your repository.
There are various pros and cons to each workflow, and it may not be obvious as to which workflow is best to choose for your project. However, the power and benefit of the workflow comes in its consistent use across all team members and collaborators during the development of the software. Provided below are a few things to consider when choosing a particular workflow.
Under the branching workflow:
- Any team member with write access to the repository can collaborate directly in adding code, revising, or testing a branch.
- Continuous integration tools such as GitHub Actions or Jenkins can be enabled for all branches of the repository in a single location, so new feature branches can automatically be tested when a pull request is opened or modified.
- It is not possible for external collaborators to contribute unless they explicitly have write access to the
spacetelescope
repository, and when external collaborators are required, repositories must adhere to ITSD policies. - It is easier to accidentally delete or overwrite the work of others who are also working on the same branch, or happen to have their own branch of the same name. While it is possible to recover this work or to restrict the editing of specific branches to only select developers, it can sometimes be a painstaking process.
- Repositories may accrue a fair amount of stale branches over time, which may become burdensome for developers, and may cause collaborators to infer that the project is not being maintained.
A forking workflow:
- Promotes "open development," wherein potential external collaborators who are interested in contributing may do so despite not having write access to the
spacetelescope
repository. - Provides a consistent experience for everyone involved in the project, whether you are an internal or an external collaborator.
- Allows for an explicit namespace in pull requests, merge commits, and repository history that makes it more apparent who "owns" which branch (e.g. "Merge pull request #1 from
<username>/<branch_name>
). - Allows for contributors to experiment with various repository settings and/or continuous integrations tools without affecting how the
spacetelescope
repository operates. - Requires extra knowledge of how to work with multiple remotes in order to keep up-to-date with the parent, 'upstream' repository, or to collaborate on someone else's fork.
- Requries that one must be explicitly added as a collaborator to someone's personal fork for direct contributions to that fork, if the person is not already a maintainer of the
spacetelescope
repository. - May result in a substantial and burdensome amount of notifications if forks are of a private repository, since everyone watching the parent repository are automatically subscribed to all of the fork activity by default.
Below we provide step-by-step instructions on how to employ each workflow.
Regardless of which workflow you chose, before contributing, you should determine if the eventual change is significant enough to warrant a GitHub issue; if you think that this change will be solving a significant problem or providing a significant enhancement to the project, then it would be advantageous to open an issue under the spacetelescope
repository. This will allow both contributors and repository maintainers to keep track of the project and capture any needed context of the particular change. Any appropriate individuals should be assigned to the issue, and any appropriate label(s) should be tagged.
Meanwhile, for trivial fixes (e.g., typos), a pull request without an accompanying issue would be acceptable.
-
Make a local copy of the
spacetelescope
repository by cloning the repository (e.g.git clone https://github.com/username/repository_name.git
). Note that, unless you explicitly delete your clone of the repository, this only has to be done once. -
Ensure that your clone is pointing to the
spacetelescope
remote repository withgit remote -v
. You should see thatorigin
corresponds to the URL from step (1). If it doesn't, you can add it withgit remote add origin https://github.com/username/repository_name.git
. -
Create a branch on the clone to develop software changes on. Branch names should be short but descriptive (e.g.
new-database-table
orfix-ingest-algorithm
), and not too generic (e.g.<username>-bug-fix
). Consistent use of hyphens is encouraged.git branch <branchname>
git checkout <branchname>
- you can use this command to switch back and forth between existing branches.- Perform local software changes using the nominal
git add
/git commit -m
cycle:git status
- allows you to see which files have changed.git add <new or changed files you want to commit>
git commit -m 'Explanation of changes you've done with these files'
-
Push the branch to the
spacetelescope
repository withgit push origin <branchname>
. -
In the
spacetelescope
repository, create a pull request for the recently pushed branch. You will want to set the "base" option to point to the branch you would like to merge changes into (e.g.master
), and the "compare" option to point to the new branch (i.e.<branchname>
). Note that if the branch is still under development, you can use the GitHub "Draft" feature (under the "Reviewers" section) to tag the pull request as a draft. Not until the "Ready for review" button at the bottom of the pull request is explicitly pushed is the pull request 'mergeable'. -
Assign the pull request a reviewer, selecting a maintainer of the
spacetelescope
repository. They will review your pull request and either accept the request and merge, or ask for additional changes. -
Iterate with your reviewer(s) on additional changes if necessary, addressing any comments on your pull request. If changes are required, you may end up iterating over steps 3.ii, 3.iii and 4 several times while working with your reviewer.
-
Once the pull request has been accepted and merged, you can delete your local branch with
git branch -d <branchname>
.
If you wish to, you can keep a branch up-to-date with the latest version of the spacetelescope
repository by checking out and merging in changes from the master
branch:
git checkout master
git pull origin master
git checkout <branchname>
git merge master
-
Create a personal fork of the
spacetelescope
repository by visiting its location on GitHub and clicking theFork
button. This will create a copy of thespacetelescope
repository under your personal GitHub account (hereby referred to as "personal fork"). Note that this only has to be done once. -
Make a local copy of your personal fork by cloning the repository (e.g.
git clone https://github.com/username/repository_name.git
, found by clicking the green "clone or download" button.). Note that, unless you explicitly delete your clone of the fork, this only has to be done once. -
Ensure that the personal fork is pointing to the
upstream
spacetelescope
repository withgit remote add upstream https://github.com/spacetelescope/repository_name.git
. Note that, unless you explicitly change the remote location of the repository, this only has to be done once. -
Create a branch on the personal clone to develop software changes on. Branch names should be short but descriptive (e.g.
new-database-table
orfix-ingest-algorithm
), and not too generic (e.g.bug-fix
). Consistent use of hyphens is encouraged.git branch <branchname>
git checkout <branchname>
- you can use this command to switch back and forth between existing branches.- Perform local software changes using the nominal
git add
/git commit -m
cycle:git status
- allows you to see which files have changed.git add <new or changed files you want to commit>
git commit -m 'Explanation of changes you've done with these files'
-
Push the branch to the GitHub repository for the personal fork with
git push origin <branchname>
. -
In the
spacetelescope
repository, create a pull request for the recently pushed branch. You will want to set the base fork pointing tospacetelescope:master
and thehead
fork pointing to the branch on your personal fork (i.e.username:branchname
). Note that if the branch is still under development, you can use the GitHub "Draft" feature (under the "Reviewers" section) to tag the pull request as a draft. Not until the "Ready for review" button at the bottom of the pull request is explicitly pushed is the pull request 'mergeable'. -
Assign the pull request a reviewer, selecting a maintainer of the
spacetelescope
repository. They will review your pull request and either accept the request and merge, or ask for additional changes. -
Iterate with your reviewer(s) on additional changes if necessary, addressing any comments on your pull request. If changes are required, you may end up iterating over steps 4.ii, 4.iii and 5 several times while working with your reviewer.
-
Once the pull request has been accepted and merged, you can delete your local branch with
git branch -d <branchname>
.
If you wish to, you can keep a personal fork up-to-date with the spacetelescope
repository by fetching and rebasing with the upstream
remote:
git checkout master
git fetch upstream master
git rebase upstream/master
Users can contribute to another user's personal fork by adding a remote
that points to their fork and using the nominal forking workflow, e.g.:
git remote add <username> <remote URL>
git fetch <username>
git checkout -b <branchname> <username>/<branchname>
- Make some changes (i.e.
add/commit
cycle) git push <username> <branchname>