9 Creating a New Repository with Rstudio
Learning Objectives
Understand what it means to create a new repository on GitHub
Successfully create a local Git repository in RStudio and push it to GitHub
Identify common errors and learn how to fix them
Step-by-Step Instructions
Open RStudio.
Go to File > New Project > New Directory > Empty Project.
Choose a folder name and directory location for your new project.
Check the box for “Create a git repository” (this initializes Git locally).
Click Create Project. Your new project will open with Git enabled.
Create or add your project files (e.g.,
README.md,.Rscripts, data).In your browser, create a new repository on GitHub.com.
- Do not initialize it with a README, license, or
.gitignore.
- Do not initialize it with a README, license, or
Back in RStudio, go to the Terminal pane and run:
git remote add origin https://github.com/yourusername/your-repo-name.git
git add.
Git commit -m “Initial Commit”
git push -u origin main
Video Tutorial
Create the Repository
Push the Repository to GitHub
Troubleshooting
Remote repository not found:
Make sure you created the repository on GitHub and copied the correct URL. RStudio does not create remote repositories.RStudio can:
Create a local Git project on your computer
Connect to an existing remote repository (one that already exists on GitHub)
Push local changes to that remote
Authentication failed:
GitHub no longer accepts passwords for HTTPS. If prompted, use a personal access token (PAT) in place of your password.Push fails due to README or file conflicts:
Make sure your GitHub repository was created without initializing it with a README, .gitignore, or license. These files can create merge conflicts when pushing from RStudio.Missing Git in RStudio:
If Git options don’t appear when creating a new project, go toTools > Global Options > Git/SVNand verify that RStudio detects Git. You may need to install Git from git-scm.com and restart RStudio.Pushed changes not showing on GitHub:
Make sure you pushed to the correct remote and branch. UseGit > Pushagain in RStudio and check your GitHub repository online to confirm.