This tool backs up your code to a cloud “repository”. It has at least three components: the cloud repository, a local repository, and software to manage the repositories. Github.com is the most widely used cloud repository. Detailed instructions on how to get started with GitHub are available. In brief, the steps are:
- Install git on your computer and create a GitHub account. Note that GitHub accounts are public unless you pay for a private account. The University of Texas also has an institutional repository for UT employees.
- Download and install a client to manage your repository. One possibility is GitHub Desktop (streamlined), another is Sourcetree (fancier). Alternatively, you can control the repository using your command line.
- Create a new repository or clone an existing one. If you want to take code that is existing on your computer and back it up to the cloud, then you’ll want to create a new repository. If you want to download code that someone else has stored in a repository, then you want to clone a repository.
- After you create a new repository and/or after you have edited files on your local computer, you will want to “commit” your changes to your local version of the repository. This involves two steps: adding or staging the file and committing the staged changes. When you commit the changes you’ll include a (usually brief) comment about what changes you made to the code.
- To back up the changes to the cloud, you’ll “push” the changes to the cloud repository.
Say that a collaborator has made changes to the code and you want to access the revised code. You will want to “pull” the changes from the cloud to your local repository. Generally you will want to get into the habit of pulling changes from the cloud repository before you make any local changes to the code. If you make changes to a file that was changed in the cloud repository since you last updated your files, you’ll need to reconcile and merge the two versions of the code. It’s not a disaster, which is a good thing because it will happen. When it happens you will have to learn more of your client’s features for reconciling conflicts.
For similar reasons you will want to be sure to commit AND PUSH your changes to the repository frequently, at least daily.
How does GitHub help?
- It keeps a record of all of the earlier versions of your code making it trivial to roll changes back to an earlier version. There is no reason to litter your directories with multiple versions of analytical files.
- You can tag versions of the code when you submit a paper so that you are always in a position to replicate a specific set of earlier results.
- You and your collaborators’ analysis files are in sync.
- Your analysis files can be synced across all your computers.
- The comments you write when you commit changes help to document code development.
- You can share your code for replication.
- It is easy to create a branch of a project when you start a new analysis that builds on old files.
There's a Nature blog posting with more detail on how git can help,
The University of Texas’s repository
The University of Texas system is designed to be used only by UT employees and is a secure location for code that you want to keep within a team of people employed by UT-Austin (including people with zero-time appointments). Each person needs to login to github by going to github.austin.utexas.edu and using their uteid and password to login. After that one can create and be added to existing github.austin.utexas.edu repositories. Note that people not employed at UT cannot access the files in this repository.