{"id":116,"date":"2025-08-29T07:24:26","date_gmt":"2025-08-29T07:24:26","guid":{"rendered":"https:\/\/blog.vyomscode.com\/?p=116"},"modified":"2025-08-29T07:24:26","modified_gmt":"2025-08-29T07:24:26","slug":"how-to-connect-a-new-codebase-with-a-private-github-repository","status":"publish","type":"post","link":"https:\/\/blog.vyomscode.com\/index.php\/2025\/08\/29\/how-to-connect-a-new-codebase-with-a-private-github-repository\/","title":{"rendered":"How to Connect a New CodeBase with a Private GitHub Repository"},"content":{"rendered":"\n<p>When you create a new  project, one of the first steps is to push it to GitHub for version control and collaboration. But sometimes, you run into a <strong>common conflict<\/strong> if your GitHub repo was initialized with a <code>README.md<\/code>.<\/p>\n\n\n\n<p>Here\u2019s a step-by-step guide to connect your project with a <strong>private GitHub repo<\/strong> and handle conflicts like a pro.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 1: Initialize Git in Your Project<\/h4>\n\n\n\n<p>Open the terminal in your project folder:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>cd YourProjectName\r\ngit init<\/em><\/code><\/pre>\n\n\n\n<p>This creates a local Git repository.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 2: Create a Private Repo on GitHub<\/h4>\n\n\n\n<ol>\n<li>Go to <a href=\"https:\/\/github.com\/?utm_source=chatgpt.com\">GitHub<\/a> \u2192 click <strong>New Repository<\/strong>.<\/li>\n\n\n\n<li>Make it <strong>Private<\/strong>.<\/li>\n\n\n\n<li>If you checked <strong>\u201cInitialize this repository with a README\u201d<\/strong>, remember \u2014 this can cause conflicts later (don\u2019t worry, we\u2019ll fix it).<\/li>\n\n\n\n<li>Copy the repo URL (HTTPS or SSH).<\/li>\n<\/ol>\n\n\n\n<p>Example:<\/p>\n\n\n\n<ul>\n<li>HTTPS \u2192 <code>https:\/\/github.com\/username\/repo-name.git<\/code><\/li>\n\n\n\n<li>SSH \u2192 <code>git@github.com:username\/repo-name.git<\/code><\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Step 3: Connect Local Repo to GitHub<\/h4>\n\n\n\n<p>Inside your project run the below command with your repo link:<\/p>\n\n\n\n<p><code><em>git remote add origin https:\/\/github.com\/username\/repo-name.git<\/em><\/code><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 4: Add and Commit Code<\/h4>\n\n\n\n<p>Now run the below command<\/p>\n\n\n\n<p><em>git add .<br>git commit -m &#8220;Initial commit &#8211; React Native app&#8221;<\/em><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 5: Handle README Conflict<\/h4>\n\n\n\n<p>Now, if your GitHub repo already has a README (and your local doesn\u2019t), pushing directly will throw an error like:<\/p>\n\n\n\n<p><code><strong>! [rejected] main -> main (fetch first)<\/strong><\/code><\/p>\n\n\n\n<h6 class=\"wp-block-heading\">\u2705 Solution: Pull and Merge First<\/h6>\n\n\n\n<p><code><strong><em>git pull origin main --allow-unrelated-histories<\/em><\/strong><\/code><\/p>\n\n\n\n<p>This pulls the remote README into your local repo and merges it. If prompted with a merge message, just save and exit.<\/p>\n\n\n\n<p>Then push again:<\/p>\n\n\n\n<p><code><strong><em>git push origin main<\/em><\/strong><\/code><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 6: Verify on GitHub<\/h4>\n\n\n\n<p>Now both your app code and the README will exist in the repo.<\/p>\n\n\n\n<p>Refresh your private repo \u2014 you should now see both:<\/p>\n\n\n\n<ul>\n<li>Your <strong>code<\/strong><\/li>\n\n\n\n<li>The <strong>README.md<\/strong> from GitHub<\/li>\n<\/ul>\n\n\n\n<p>\ud83c\udf89 You\u2019re done!<\/p>\n\n\n\n<p>&#8211; <a href=\"https:\/\/tripti.vyomscode.com\/\" data-type=\"link\" data-id=\"https:\/\/tripti.vyomscode.com\/\">Tripti<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you create a new project, one of the first steps is to push it to GitHub for version control and collaboration. But sometimes, you run into a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.vyomscode.com\/index.php\/wp-json\/wp\/v2\/posts\/116"}],"collection":[{"href":"https:\/\/blog.vyomscode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.vyomscode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.vyomscode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.vyomscode.com\/index.php\/wp-json\/wp\/v2\/comments?post=116"}],"version-history":[{"count":1,"href":"https:\/\/blog.vyomscode.com\/index.php\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"predecessor-version":[{"id":117,"href":"https:\/\/blog.vyomscode.com\/index.php\/wp-json\/wp\/v2\/posts\/116\/revisions\/117"}],"wp:attachment":[{"href":"https:\/\/blog.vyomscode.com\/index.php\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.vyomscode.com\/index.php\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.vyomscode.com\/index.php\/wp-json\/wp\/v2\/tags?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}