Create and Clone a Git Repository
This tutorial provides a step-by-step guide for creating repositories on GitHub and cloning them to your local computer. GitHub repositories are remote storage spaces that allow you to track script changes, collaborate with colleagues, and document your research process. Public repositories can also be cloned by others to facilitate reproducibility and collaboration.
Requirements and Necessary Software
- GitHub Account: Click “Sign up” and follow the instructions.
- R and RStudio (see previous chapter)
- GitHub Desktop: Install and sign in.
Creating a Repository on GitHub
Sign in to GitHub. Click the “+” icon at the top right and select New repository.
Enter repository details:
Name your repository and provide a brief description.
Choose public or private visibility.
Select initialization options.
- A
README
is recommended for basic project documentation. For formatting tips, see Chapter 8 of Data Management in Large-Scale Education Research. .gitignore
lets you exclude specific files from version control (e.g.,.Rhistory
or local.csv
files). See Git’s documentation.- A license defines how others may use your code. The MIT License is commonly used. For guidance, visit choosealicense.com.
- A
Click Create repository to finish.
Cloning a Repository via Git Bash
Visit the repository you want to clone.
Example: Advanced Epidemiological Methods by Dr. Ehsan Karim.
Click the green < > Code button and copy the HTTPS link.
Open Git Bash.
Navigate to the target directory:
Use
pwd
to check your current path.Use
cd
to move to your preferred folder.
The path after
~
shows your current location.Run the clone command:
Cloning a Repository via RStudio
Go to the GitHub repository and copy the HTTPS URL.
Open RStudio: File > New Project
Select Version Control.
Then choose Git.
Complete the Git project setup:
Paste the HTTPS link under Repository URL.
Optionally, edit the Project directory name.
Click Browse to choose a folder (e.g., your Desktop).
Click Create Project to finish.
The cloned repository will now be available in your selected folder.