{"id":80255,"date":"2025-05-29T11:14:26","date_gmt":"2025-05-29T05:44:26","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=80255"},"modified":"2025-09-09T15:56:10","modified_gmt":"2025-09-09T10:26:10","slug":"steps-to-upload-your-project-to-github-using-git","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/steps-to-upload-your-project-to-github-using-git\/","title":{"rendered":"How to Upload Your Source Code to GitHub Using Git in VS Code (With Error Fixes)"},"content":{"rendered":"\n<p>So you\u2019ve built something awesome and now want to upload it to GitHub using Git in <strong>Visual Studio Code<\/strong>? Great choice!<\/p>\n\n\n\n<p>This guide will walk you through <strong>step-by-step commands<\/strong> for uploading your project using Git, and we\u2019ll also cover <strong>common errors<\/strong> you may face along the way, plus how to fix them.<\/p>\n\n\n\n<p>Let\u2019s get your project online! <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Prerequisites<\/strong><\/h2>\n\n\n\n<p>Before we start, make sure you have:<\/p>\n\n\n\n<ul>\n<li>Git installed \u2013<a href=\"https:\/\/git-scm.com\/\" target=\"_blank\" rel=\"noreferrer noopener\"> Install Git<br><\/a><\/li>\n\n\n\n<li>VS Code installed \u2013<a href=\"https:\/\/code.visualstudio.com\/\" target=\"_blank\" rel=\"noreferrer noopener\"> Download VS Code<br><\/a><\/li>\n\n\n\n<li>A <a href=\"https:\/\/www.guvi.in\/blog\/how-to-use-github-repositories\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a> account \u2013<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\"> Create one here<br><\/a><\/li>\n\n\n\n<li>A local project folder is ready to upload<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Step-by-Step: Uploading Your Source Code to GitHub using Git<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/06\/2@2x-2-1200x630.png\" alt=\"Uploading Your Source Code to GitHub\" class=\"wp-image-80837\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/06\/2@2x-2-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/06\/2@2x-2-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/06\/2@2x-2-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/06\/2@2x-2-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/06\/2@2x-2-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/06\/2@2x-2-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Open the Project in VS Code<\/strong><\/h3>\n\n\n\n<p>Open your project folder in VS Code, then open the <strong>Terminal<\/strong> (Ctrl + ~ or from the menu Terminal &gt; New Terminal).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Initialize Git in the Project<\/strong><\/h3>\n\n\n\n<p>git init<\/p>\n\n\n\n<p>This creates a hidden .git folder and turns your project into a Git repository.<\/p>\n\n\n\n<p><strong>Find out: <a href=\"https:\/\/www.guvi.in\/blog\/git-interview-questions-and-answers\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best Git Interview Questions and Answers<\/a><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Add All Files to Git<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>git add .<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>This stages all files to be committed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Make Your First Commit<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>git commit -m &#8220;Initial commit&#8221;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>This saves your current version as a snapshot.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Create a GitHub Repository<\/strong><\/h3>\n\n\n\n<p>Go to<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\"> github.com<\/a>:<\/p>\n\n\n\n<ul>\n<li>Click <strong>&#8220;New repository.&#8221;<\/strong><strong><br><\/strong><\/li>\n\n\n\n<li>Name your repo<br><\/li>\n\n\n\n<li>DO NOT check the boxes for <code>README<\/code>, <code>.gitignore<\/code>, or <code>license<\/code><br><\/li>\n<\/ul>\n\n\n\n<p>Click <strong>Create repository<\/strong><\/p>\n\n\n\n<p><strong>Explore: <a href=\"https:\/\/www.guvi.in\/blog\/git-flow-and-version-control-best-practices\/\" target=\"_blank\" rel=\"noreferrer noopener\">Git Flow Basics: Best Practices for Smooth Version Control<\/a><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Connect Your Local Repo to GitHub<\/strong><\/h3>\n\n\n\n<p>Copy the repository URL from GitHub. It looks like:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>https:\/\/github.com\/your-username\/your-repo-name.git<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Back in VS Code terminal:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>git remote add origin https:\/\/github.com\/your-username\/your-repo-name.git<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>7. Set Branch to Main (Optional but Recommended)<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>git branch -M main<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>This ensures your local branch is named main, matching GitHub\u2019s default.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>8. Push Your Code to GitHub<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>git push -u origin main<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Your code is now on GitHub!<\/p>\n\n\n\n<p><strong>Discover: <a href=\"https:\/\/www.guvi.in\/blog\/how-to-use-github-repositories\/\" target=\"_blank\" rel=\"noreferrer noopener\">A Beginner&#8217;s Guide to GitHub Repositories and File Sharing<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Git Errors and How to Fix Them<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Error: fatal: not a git repository<\/strong><\/h3>\n\n\n\n<p><strong>Cause:<\/strong> You&#8217;re running Git commands in a folder where Git hasn\u2019t been initialized.<\/p>\n\n\n\n<p><strong>Fix:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>git init<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Error: remote origin already exists<\/strong><\/h3>\n\n\n\n<p><strong>Cause:<\/strong> You already set a remote, but you&#8217;re trying to add it again.<\/p>\n\n\n\n<p><strong>Fix:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>git remote remove origin<br>git remote add origin https:\/\/github.com\/your-username\/your-repo-name.git<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Error: error: failed to push some refs to&#8230;<\/strong><\/h3>\n\n\n\n<p><strong>Cause:<\/strong> Your local branch and GitHub branch have diverged or conflicts exist.<\/p>\n\n\n\n<p><strong>Fix:<\/strong> First, try pulling changes:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>git pull origin main &#8211;allow-unrelated-histories<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Then push again:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>git push -u origin main<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Error: Repository not found or Permission denied<\/strong><\/h3>\n\n\n\n<p><strong>Cause:<\/strong> Either the repo URL is wrong, or you\u2019re not authenticated correctly.<\/p>\n\n\n\n<p><strong>Fix:<\/strong><\/p>\n\n\n\n<ul>\n<li>Double-check the URL<br><\/li>\n\n\n\n<li>Make sure you&#8217;re logged in to GitHub in VS Code<br><\/li>\n\n\n\n<li>If using SSH, ensure your SSH keys are set up correctly<br><\/li>\n<\/ul>\n\n\n\n<p>You can also switch to HTTPS if SSH is causing issues.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Error: branch &#8216;main&#8217; does not exist<\/strong><\/h3>\n\n\n\n<p><strong>Cause:<\/strong> You&#8217;re trying to push a branch that doesn\u2019t exist locally.<\/p>\n\n\n\n<p><strong>Fix:<\/strong> Check your branch name with:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>git branch<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>If you&#8217;re on master, either rename:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>git branch -M main<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Or push using:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>git push -u origin master<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">All Git Commands Recap<\/h2>\n\n\n\n<p>Here\u2019s the full list of Git commands you&#8217;ll use:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>git init<br>git add .<br>git commit -m &#8220;Initial commit&#8221;<br>git branch -M main<br>git remote add origin https:\/\/github.com\/your-username\/your-repo-name.git<br>git push -u origin main<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Final Tips<\/h2>\n\n\n\n<ul>\n<li>Use a <code>.gitignore<\/code> file to avoid pushing unwanted files like <code>node_modules\/<\/code>, <code>.env<\/code>, etc.<br><\/li>\n\n\n\n<li>Always commit meaningful changes with clear commit messages.<br><\/li>\n\n\n\n<li>You can repeat <code>git add<\/code> ., <code>git commit<\/code>, and <code>git push<\/code> to update your GitHub repo anytime.<br><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Getting Started with Guvi<\/h2>\n\n\n\n<p>Enroll in Guvi&#8217;s course on <a href=\"https:\/\/www.guvi.in\/courses\/it-and-software\/git\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=8+Easy+Steps+to+Upload+Your+Source+Code+to+GitHub+Using+Git\" target=\"_blank\" rel=\"noreferrer noopener\">Git<\/a> to learn more about Git commands and their uses. Git plays a major role in a developer&#8217;s life; this course provides a detailed guide on how to use Git locally on your machine. It covers beginner concepts, such as managing local repositories and the difference between Git and GitHub to advanced concepts such as merging and audit trails, along with professional certification.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">You Did It!<\/h2>\n\n\n\n<p>You\u2019ve now successfully uploaded your project to GitHub using Git in VS Code. If you ran into an error, don\u2019t worry \u2014 every developer does at some point. Bookmark this guide or share it with your coding buddies!<\/p>\n\n\n\n<p>Happy coding, and see you on GitHub! <\/p>\n","protected":false},"excerpt":{"rendered":"<p>So you\u2019ve built something awesome and now want to upload it to GitHub using Git in Visual Studio Code? Great choice! This guide will walk you through step-by-step commands for uploading your project using Git, and we\u2019ll also cover common errors you may face along the way, plus how to fix them. Let\u2019s get your [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":80836,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[714],"tags":[],"views":"4762","authorinfo":{"name":"Arun Kumar","url":"https:\/\/www.guvi.in\/blog\/author\/arun-kumar\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/06\/1-4-300x116.png","jetpack_featured_media_url":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/06\/1-4.png","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/80255"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=80255"}],"version-history":[{"count":11,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/80255\/revisions"}],"predecessor-version":[{"id":86747,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/80255\/revisions\/86747"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/80836"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=80255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=80255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=80255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}