8  Creating a New Repository with VSCode

Learning Objectives

  • Understand what it means to create a new repository on GitHub

  • Successfully create a local Git repository in VSCode and push it to GitHub

  • Identify common errors and learn how to fix them

Step-by-Step Instructions

Part 1: Create a Local Repository in VSCode

  1. Open Visual Studio Code (VSCode).

  2. Create a new folder on your computer and open it in VSCode.

  3. Inside VSCode, go to View > Source Control or click the Source Control icon on the left sidebar.

  4. Click Initialize Repository to turn the folder into a local Git repository.

  5. Create or add your project files (e.g., README.md, .py, .R, or .ipynb files).

Part 2: Create a Repository on GitHub

  1. In your browser, go to GitHub.com and sign in.

  2. Click the + icon in the upper-right and select New Repository.

  3. Name your repository (e.g., my-new-repo).

  4. Important: Do not initialize the repo with a README, .gitignore, or license (this prevents conflicts).

  5. Click Create Repository.

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.

Additonal Resources