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
Open Visual Studio Code (VSCode).
Create a new folder on your computer and open it in VSCode.
Inside VSCode, go to View > Source Control or click the Source Control icon on the left sidebar.
Click Initialize Repository to turn the folder into a local Git repository.
Create or add your project files (e.g.,
README.md,.py,.R, or.ipynbfiles).
Part 2: Create a Repository on GitHub
In your browser, go to GitHub.com and sign in.
Click the + icon in the upper-right and select New Repository.
Name your repository (e.g.,
my-new-repo).Important: Do not initialize the repo with a README,
.gitignore, or license (this prevents conflicts).Click Create Repository.
Part 3: Link and Push to GitHub
In VSCode, open the Terminal (View > Terminal).
In the Terminal type:
git remote add origin https://github.com/vmahan1998/GitHub_Basic_Skills_Create_Repo_Test_VSCode.git
git branch -M main
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.