If you haven’t set up git and GitHub yet do that first. If you’ve done this, you now know why you should use git and Github, but how do you actually start using all these things you just got setup?
If you’re starting a new research project you’ll want to set up a GitHub repository (repo) for it from the get go. Doing it from the start is ideal, but if you’re moving an existing project to GitHub see the next section.
Make the repo on GitHub
Go to the WWS GitHub organization ((https://github.com/orgs/wildfire-water-security/repositories).
Click the green ‘New repository’ button in the right corner.
Give your repo a name. It should take the form WWS-Node#-ProjectCode-ProjectKeywords where:
Give the repo a description to provide some more information about the project.
Set the repo as public or private. Private repos are still viewable by the entire WWS organization.
Click the box to initialize the README file. This will be the landing page for the repo where you can store links for important files, share important information, and provide contact information for the project. We’ll discuss more on that in another tutorial.
If you’d like you can add a .gitignore or a license, but if you’re not sure, skip these you can always add them later.
Create the repository by clicking the green button on the bottom.
Now that your project exists on GitHub, lets get it on your local computer. To do this, go to GitHub desktop got to file -> clone repository (CRTL + SHIFT + O).
This will open up a box, where you can select the GitHub repository you want to put on your computer, and where you want those files located.
Now if you go to the location where you specified as the local path above, you should see a folder that looks like this:
Store all your project files here to take advantage of all that GitHub has to offer. We’ll talk about maintaining a repo in the next tutorial.
If you already have a folder for an existing research project, all your stuff is there, but now you want it on GitHub so you can take advantage of the version control and collaborative features. Here’s how to do that:
It’s recommended that you turn your folder into an R project if you haven’t already done so.
Why? R projects makes data more shareable: data stored in project is easily findable with relative file paths (meaning that the path will work even if the project gets moved to different places). To do that run the following code:
#install.package("usethis") #only need to run the first time
library(usethis)
#the location you of your project folder
local_dir <- "file path to project folder"
#create a project from the directory
usethis::create_project(local_dir)
usethis::use_git()
Next you’ll want to go to GitHub desktop. Go to file -> add local repository (CTRL+O), navigate to your project directory and hit add repository.
It will link this folder to your GitHub desktop. On the right side you should all the files in your project folder ready to commit. At this point your files are linked to git, but they’re not stored on GitHub.
To link your repository to GitHub so it’s backed up online, you’ll want to publish the repository by clicking the button in the right corner. It’ll prompt you to give the repository a name, it should take the form WWS-Node#-ProjectCode-ProjectKeywords where:
Then hit the blue “Publish repository” button.
We now need to save our first set of files to the repository (a commit) and save it GitHub (a push). This will save a copy of all your files to Github.
Lastly, we need to upload or push these changes to GitHub so they’re backed up online. Do this by hitting the “Publish Branch” button on the top right.
Now all your files are backed up, version controlled, and accessible by the whole project! You can see you files on the repository on GitHub online.
Hester, J. B., the STAT 545 TAs, Jim. (n.d.). Let’s Git started | Happy Git and GitHub for the useR. Retrieved from https://happygitwithr.com/
How to create your first GitHub repository: A beginner’s guide | Tutorial. (2024). Retrieved from https://www.youtube.com/watch?v=-RZ03WHqkaY