Contribute to other projects

Lots of scientific software is hosted online in Git repositories. Now that you know the basics of Git, you can directly contribute to developing the scientific software you use for your research (Fig. \ref{fig:Fig4}). From a small contribution like fixing a typo in the documentation to a larger change such as fixing a bug, it is empowering to be able to improve the software used by you and many other scientists.

When contributing to a larger project with many contributors, you will not be able to push your changes with git push directly to the project’s remote repository. Instead you will first need to create your own remote copy of the repository, which on GitHub is called a fork (Box 1). You can fork any repository on GitHub by clicking the button “Fork” on the top right of the page (see help.github.com/articles/fork-a-repo).

Once you have a fork of a project’s repository, you can clone it to your computer and make changes just like a repository you created yourself. As an exercise, you will add a file to the repository that we used to write this paper. First, go to github.com/jdblischak/git-for-science and choose the “Fork” option to create a git-for-science repository under your GitHub account (Fig. \ref{fig:Fig4}B). In order to make changes, download it to your computer with the command git clone from the directory you wish the repo to appear in (Fig. \ref{fig:Fig4}C).

$ git clone https://github.com/username/git-for-science.git

Now that you have a local version, navigate to the subdirectory readers and create a text file named as your GitHub username (Fig. \ref{fig:Fig4}D).

$ cd git-for-science/readers $ touch username.txt

Add and commit this new file (Fig. \ref{fig:Fig4}D), and then push the changes back to your remote repository on GitHub (Fig. \ref{fig:Fig4}E).

$ git add username.txt $ git commit -m "Add username to directory of readers." $ git push origin master

Currently, the new file you created, readers/username.txt , only exists in your fork of git-for-science. To merge this file into the main repository, send a pull request using the GitHub interface (Pull request ->New pull request ->Create pull request; Fig. \ref{fig:Fig4}F; see help.github.com/articles/using-pull-requests). After the pull request is created, we can review your change and then merge it into the main repository. Although this process of forking a project’s repository and issuing a pull request seems like a lot of work to contribute changes, this workflow gives the owner of a project control over what changes get incorporated into the code. You can have others contribute to your projects using the same workflow.

The ability to use Git to contribute changes is very powerful because it allows you to improve the software that is used by many other scientists and also potentially shape the future direction of its development.