Creating a repository
Overview
Teaching: 5 min
Exercises: 10 minQuestions
How to start a project with version control?
Objectives
Create a repository on GitHub
Understand the options about README, license and .gitignore
Create a repository
When working on a project, one typically uses a project folder to contain the project files, scripts and data. In GitHub, such a project folder is called a repository. Hence, a new project starts with a new repository. First of all, you need to sign in to GitHub.com:
a new repository or project can be started by either:
- Click
Start a project
- Click on the
+
sign in the top right corner - Click
New repository
When creating a repository, some elements need to be defined:
- Repository name: Choose something meaningful, without spaces
- Description: Short one-line sentence describing what your project is all about
- Public/private: You can decide whether the repository is going to be private or public. When public, a repository can be viewed and forked by anyone. Some functionalities (e.g., GitHub pages) may require the repository to be public. You can later change this option in the repository visibility settings
- README.md: A Readme is a crucial element of a repository, as it provides the introduction information for other users to get started
- .gitignore: This file describes which files that should not be tracked by Git. For the moment, you have not to select this and keep it on None as we will use Rstudio to provide the
.gitignore
file in episode 2. - LICENSE: for scientific work, a BSD or MIT license are probably most appropriate. Check the choose a license website for more information on open source licenses.
Create a repository
- Go to GitHub and login
- Follow this tutorial to create a repo and create your first (online) commit to your repository
Clone a repo to work locally
We have initiated a repository online. Hence, we can start working on the code locally by downloading the repository to our computer. Rstudio provides a convenient way to start a new project as a Git repository.
To get the https link, you need to click the green button and make sure to copy paste the link with as title Clone with HTTPS
:
Start new R project from repository
- On your GitHub repository page, copy the repository HTTPS url (check the green button on your repo page)
- In Rstudio,
File > New Project...
, selectVersion Control
, chooseGit
- Provide the repository HTTPS link you just copied (the project name will be filled in as well)
- Browse to the desired directory where you will manage your project/code
An example of the project setup using an existing Git repository:
Check folder content on local machine
In your File explorer, search for your project folder and check the content. Does this corresponds to what is shown online on your repository website?
Key Points
Initiate a new project in GitHub
Start the project in Rstudio from Git