{"id":1438,"date":"2024-08-16T16:45:51","date_gmt":"2024-08-16T16:45:51","guid":{"rendered":"https:\/\/datatype.co.in\/blog\/?p=1438"},"modified":"2026-03-31T02:09:52","modified_gmt":"2026-03-31T02:09:52","slug":"how-to-push-code-to-github-repository","status":"publish","type":"post","link":"https:\/\/datatype.co.in\/blog\/how-to-push-code-to-github-repository\/","title":{"rendered":"How to Push Code to GitHub Repository"},"content":{"rendered":"\n<p>If you have a project in your local machine\/laptop and you want to push the code to GitHub, then follow the below steps:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1:<\/h3>\n\n\n\n<p>Create a repository in <a href=\"https:\/\/github.com\/\">GitHub<\/a>. In order to create a repository in GitHub, you should have an account. If you don&#8217;t have a GitHub account, sign-up.<\/p>\n\n\n\n<p>Login to GitHub, click on <strong>New<\/strong> button and fill the <strong>Create a new repository<\/strong> form. Enter repository name and mark the repository as <strong>Private<\/strong> if you don&#8217;t want it to be publicly accessible.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"922\" height=\"845\" src=\"https:\/\/datatype.co.in\/blog\/wp-content\/uploads\/2024\/08\/image.png\" alt=\"\" class=\"wp-image-1442\" srcset=\"https:\/\/datatype.co.in\/blog\/wp-content\/uploads\/2024\/08\/image.png 922w, https:\/\/datatype.co.in\/blog\/wp-content\/uploads\/2024\/08\/image-300x275.png 300w, https:\/\/datatype.co.in\/blog\/wp-content\/uploads\/2024\/08\/image-768x704.png 768w, https:\/\/datatype.co.in\/blog\/wp-content\/uploads\/2024\/08\/image-710x651.png 710w\" sizes=\"auto, (max-width: 922px) 100vw, 922px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: <\/h3>\n\n\n\n<p>Once the GitHub repository is created, copy the repository url. Go to local project <strong>root directory<\/strong>, open a terminal and run the following commands in given sequence-<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git init\ngit add README.md\ngit commit -m \"first commit\"\ngit branch -M main\ngit remote add origin https:\/\/github.com\/&#91;user-name]\/&#91;repository-name].git\ngit push -u origin main<\/code><\/pre>\n\n\n\n<p>This will push your code to remote GitHub repository.<\/p>\n\n\n\n<p>If you already have source code that is pointing to some other GitHub repository, and you want to push the code in your GitHub repository then follow the below steps-<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git remote add origin https:\/\/github.com\/&#91;user-name]\/&#91;repository-name].git\ngit branch -M main\ngit push -u origin main\n\n<\/code><\/pre>\n\n\n\n<p>Now the code will point to your GitHub repository. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have a project in your local machine\/laptop and you want to push the code to GitHub, then follow the below steps: Step 1: Create a repository in GitHub.&nbsp;[ &hellip; ]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[266,265],"tags":[],"class_list":["post-1438","post","type-post","status-publish","format-standard","hentry","category-git","category-vcs","list-style-post"],"_links":{"self":[{"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/posts\/1438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/comments?post=1438"}],"version-history":[{"count":3,"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/posts\/1438\/revisions"}],"predecessor-version":[{"id":1443,"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/posts\/1438\/revisions\/1443"}],"wp:attachment":[{"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/media?parent=1438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/categories?post=1438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/tags?post=1438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}