How to Save a Visual Studio Project to GitHub

In this article, I will guide you on how to save a Visual Studio project, whether it’s a console app, API, or any.NET project, to GitHub.


Steps to Save Your Project

1. Set Up Your GitHub Account

  • Head to GitHub.

  • If you don’t have an account, register and follow the prompts to create one.

  • If you already have an account, log in. Your interface should look like the image below.

2. Create a New Repository

  • Locate the green "Create New Repository" button, as shown in the image below, and click it.

  • Fill in the repository details:

    • Repository Name: Use the exact name of your project in Visual Studio for better synchronization.

    • Description: Add a brief description explaining your project.

    • README File (Optional): Check the box if you want to include a README to provide more technical details.

    • Visibility: Choose between public (accessible to everyone) or private (restricted access).

    • GitIgnore Template: Select Visual Studio to exclude unnecessary files during the push.

  • Click Create Repository to finalize.


Setting Up Your Local Project

3. Clone the Repository to Your Local Folder

  • Navigate to your project folder and create a new folder, e.g.,MyRepoProject

  • Open the command prompt and cd into the newly created folder:

      cd path-to-MyRepoProject
    
  • Go back to your GitHub repository, click the green "Code" button, and copy the HTTPS link.

  • In the command prompt, type:

      git clone [paste-the-link]
    
  • This will clone the GitHub repository to your local folder.

4. Set Up Your Project in Visual Studio

  • Navigate to the cloned repository folder (MyRepoProject).

  • Open Visual Studio and create a new project inside this folder.

  • After creating the project, your file structure should resemble the one shown below.


Pushing Your Project to GitHub

5. Add, Commit, and Push

  • Open the command prompt or Visual Studio terminal, ensuring you're in the console App folder directory within the ⁣MyRepoProject directory.

  • Run the following commands:

    1. Add all changes:

       git add .
      

    2. Commit your changes with a message:

       git commit -m "Commit message"
      

    3. Push your changes to GitHub:

       git push
      

This will successfully push your code to GitHub.

6. Making Future Updates

For any subsequent changes, navigate back to the same project folder in the command line and repeat these three commands (git add, git commit, and git push) to update your changes to your GitHub repository.


Attributions

And specifically, I would like to thank @SundayOladiran, my tutor, for the great work done for me.


Thank You!

Thank you for reading. I hope this guide helps you save your Visual Studio projects to GitHub with ease.