forked from jdblischak/git-for-science
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contribute-to-other-projects.tex
41 lines (31 loc) · 3.15 KB
/
contribute-to-other-projects.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
\section*{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 \verb|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 \href{https://help.github.com/articles/fork-a-repo/}{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 \href{https://github.com/jdblischak/git-for-science}{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 \verb|git clone| from the directory you wish the repo to appear in (Fig. \ref{fig:Fig4}C).
\begin{verbatim}
$ git clone https://github.com/username/git-for-science.git
\end{verbatim}
Now that you have a local version, navigate to the subdirectory \verb|readers| and create a text file named as your GitHub username (Fig. \ref{fig:Fig4}D).
\begin{verbatim}
$ cd git-for-science/readers
$ touch username.txt
\end{verbatim}
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).
\begin{verbatim}
$ git add username.txt
$ git commit -m "Add username to directory of readers."
$ git push origin master
\end{verbatim}
Currently, the new file you created, \verb|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 -\textgreater New pull request -\textgreater Create pull request; Fig. \ref{fig:Fig4}F; see \href{https://help.github.com/articles/using-pull-requests/}{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.