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

  1. Open RStudio.

  2. Go to File > New Project > New Directory > Empty Project.

  3. Choose a folder name and directory location for your new project.

  4. Check the box for “Create a git repository” (this initializes Git locally).

  5. Click Create Project. Your new project will open with Git enabled.

  6. Create or add your project files (e.g., README.md, .R scripts, data).

  7. In your browser, create a new repository on GitHub.com.

    • Do not initialize it with a README, license, or .gitignore.
  8. 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 to Tools > Global Options > Git/SVN and 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. Use Git > Push again in RStudio and check your GitHub repository online to confirm.

Additional Resources