ETC5513: Collaborative and Reproducible Practices
Tutorial 9
Introduction
In this tutorial, we will cover the following topics:
- Creating a Git repository from existing work using
git init
and setting up the remote. - Adding a license to your repository on GitHub.
Setting Up a New Project in RStudio
To begin, we will set up a new project in RStudio without using version control.
Step 1: Create a New Project
- Open RStudio.
- Go to the top menu and select
File
>New Project...
. - In the “New Project” wizard, select
New Directory
. - Choose
New Project
. - Enter a name for your project and select a location on your computer where you want to save it.
- Click
Create Project
.
You now have a new RStudio project set up without version control
Creating a Git Repository from Existing Work
If you have an existing project that you want to version control with Git, follow these steps:
Step 1: Initialize the Git Repository
- Open your terminal or command prompt.
- Navigate to the root directory of your existing project using the
cd
command. For example:bash cd path/to/your/project
- Initialize a new Git repository in this directory by running:
bash git init
This command creates a new subdirectory named.git
that contains all of your necessary repository files.
Step 2: Add Your Files to the Repository
Not all of our files should be added to git. For example, the
.Rproj.user.
folder should be left out. Create a new text file called.gitignore
and add the pattern.Rproj.user/
to ignore. Test if this is working usinggit status
Add all of your project files to the staging area:
bash git add .
Commit the files to the repository with a descriptive message:
bash git commit -m "Initial commit"
Step 3: Set Up the Remote Repository
- Go to GitHub and create a new repository. Do not initialize it with a README, .gitignore, or license.
- Copy the URL of the new GitHub repository.
- In your terminal, add the remote repository URL to your local repository:
bash git remote add origin git@github.com:your-username/your-repository.git
- Push your local repository to GitHub:
bash git push -u origin main
You should now be able to see your repository on GitHub.
Adding a License on GitHub
Adding a license to your repository is important for defining how others can use your code. Follow these steps to add a license:
Step 1: Choose a License
- Go to Choose a License to find a license that suits your needs.
- Copy the text of the license you choose.
Step 2: Add the License to Your Repository
Method 1: Using RStudio
Licenses are just plain text files (like gitignore
).
Create a new text file in RStudio, and past the contents of the license you chose.
Save the license as LICENSE (with no extension)
Add and commit the files, and push to GitHub
git add LICENSE git commit -m "Add license" git push origin main
Check if you can see the license file on GitHub
Method 2: Using GitHub
- In your GitHub repository, click on the “Add file” button and select “Create new file”.
- Name the file
LICENSE
(orLICENSE.md
if you prefer Markdown format). - Paste the license text into the file.
- Scroll down and click “Commit new file” to add the license to your repository.
GitHub will also suggest you some licenses. If these suit your needs, you can just use those.
Conclusion
You have now successfully set up a new project in RStudio, created a Git repository from existing work, set up the remote, and added a license to your GitHub repository. These steps are fundamental for managing your projects and collaborating with others in a reproducible manner.