{"id":3131,"date":"2020-08-17T05:35:02","date_gmt":"2020-08-17T05:35:02","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=3131"},"modified":"2020-08-17T06:39:10","modified_gmt":"2020-08-17T06:39:10","slug":"git-basic-commands","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/git-basic-commands\/","title":{"rendered":"GIT Basic Commands"},"content":{"rendered":"<h2>Introduction to GIT<\/h2>\n<p>Git is a content <a href=\"https:\/\/studysection.com\/blog\/quick-introduction-to-project-management\/\">management<\/a> and tracking system. It is a distributed revision control that is performed on stored data. It is a Source Code Management (SCM) system. It allows you to track the history of files. We can create different versions of this collection.<br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2020\/08\/git-remote-repo.png\" alt=\"git remote repo\"\/><\/p>\n<h3>What we will cover in this post:<\/h3>\n<ul>\n<li>Basic commands of Git<\/li>\n<li>How to make changes in the files<\/li>\n<li>Sync my local repository with the remote repository<\/li>\n<li>Add\/commit them<\/li>\n<\/ul>\n<h3>Below is the list of some basic Git commands to get you going with Git:<\/h3>\n<ol>\n<li>Git Config: It configures the author name and email address that will be used with your commits.<br \/>\n\t\t<em>git config &#8211;global user.name &#8220;Abc Xyz&#8221;<br \/>\ngit config &#8211;global user.email abc@example.com<\/em><\/li>\n<li>Git Init: It will create a new Local Repository.<br \/>\n\t\t<em>git init<\/em><\/li>\n<li>Git Clone: It will create a working copy of a local repository.<br \/>\n<em>git clone \/path\/to\/repository<\/em><\/li>\n<li>Git Add: It adds one or more files to staging.<br \/>\n<em>git add &lt;filename><\/em>   \/\/to add a particular file<br \/>\n<em>git add * <\/em>    \/\/to add all the files<\/li>\n<li>Git Commit: It commits the changes to the head but not yet to the remote repository.<br \/>\n\t\t<em>git commit -m &#8220;Commit Comment&#8221;<\/em><\/li>\n<li>Git Push: It will send the changes to the master branch of your remote repository.<br \/>\n\t\t<em>git push origin master<\/em><\/li>\n<li>Git Status: It will list all the files you&#8217;ve changed &#038; those you still need to add or commit.<br \/>\n\t\t<em>git status<\/em><\/li>\n<li>Git Checkout\/Branch: To create branches and to switch between them.<br \/>\n\t\t\/\/Switch from one branch to another<br \/>\n\t\t<em>git checkout &lt;branch><\/em><br \/>\n\t\t\/\/Create a new branch and switch to it<br \/>\n\t\t<em>git checkout -b &lt;branch><\/em><br \/>\n\t\t\/\/List all the branches in your repository &#038; tells you what branch you&#8217;re currently in<br \/>\n\t\t<em>git branch<\/em><br \/>\n\t\t\/\/Delete the feature branch<br \/>\n\t\t<em>git branch -d &lt;branch><\/em><br \/>\n\t\t\/\/Push the branch to your remote repository<br \/>\n\t\t<em>git push origin &lt;branch><\/em><\/li>\n<li>Git Pull: It will Fetch and merge changes from the remote server to your working directory.<br \/>\n\t\t<em>git pull<\/em><\/li>\n<li>Git Merge: It will merge a different branch into your current branch.<br \/>\n<em>git merge &lt;branch><\/em>\t\t<\/li>\n<li>Git Add: After making changes to resolve conflicts manually, you mark the changed file.<br \/>\n<em>git add &lt;filename><\/em>\t<\/li>\n<li>Git Diff: It will show you the merge changes.<br \/>\n\t\t\/\/View all the merge conflicts<br \/>\n\t\t<em>git diff<\/em><br \/>\n\t\t\/\/View the conflicts against the base file<br \/>\n\t\t<em>git diff &#8211;base &lt;filename><\/em><br \/>\n\t\t\/\/Preview changes, before merging<br \/>\n\t\t<em>git diff &lt;source-branch> &lt;target-branch><\/em><\/li>\n<\/ol>\n<h3>The basic workflow of Git:<\/h3>\n<p>Step 1 \u2212 Modify Local files.<br \/>\nStep 2 \u2212 Add these files to the staging area.<br \/>\nStep 3 \u2212 Commit these files will move them from the staging area. After Push operation, it stores the changes permanently to the Git repository.<\/p>\n<h3>Step by Step commands to commit your code:<\/p>\n<h3>\n<ol>\n<li>Check status if you are in your branch or not.<br \/>\n<em>git status<\/em><\/li>\n<li>If you are not in your branch which you want to commit (If you are already in your branch you can skip this step). Go to your branch using-<br \/>\n\t\t<em>git checkout &lt;your branch name><\/em><\/li>\n<li>Add the files you want to commit. This will take files to the staging area, not on the repository.<br \/>\n\t\t<em>git add &#8211;all <\/em>   \/\/to add all files<br \/>\n<em>git add .  <\/em>    \/\/to add all files<br \/>\n<em>git add &lt;filename><\/em>\t\/\/particular file<\/li>\n<li>Now use below command, to push code to the repository.<br \/>\n\t\t<em>git push origin &lt;your-branch-name><\/em><\/li>\n<\/ol>\n<h3>Step by Step commands to take a pull from the remote repository to your local:<\/h3>\n<ol>\n<li>Check status whether your directory is clean or not. It means your directory should not contain any file that is not committed to your branch.<br \/>\n\t\t<em>git status<\/em><\/li>\n<li>If it is not, use the above steps (Step by Step commands to commit your code) to commit your changes.<\/li>\n<li>If directory is clean, pull the code from remote repo<br \/>\n\t\t<em>git pull origin master<\/em><\/li>\n<li>This will merge the master\u2019s code to your local. You have to solve conflicts if occurred manually from local files. Then commit merged code to your branch-<br \/>\n\t\t<em>git push origin &lt;your-branch-name><\/em><\/li>\n<\/ol>\n<p><strong>Step by Step commands to create a new branch:<\/strong><\/p>\n<ol>\n<li>Pull code from Remote repository using-<br \/>\n<em>git pull origin master<\/em><\/li>\n<li>Now, the common remote code will be on your local. Then create your new branch using-<br \/>\n<em>git checkout -b \u201cnew_branch\u201d<\/em><\/li>\n<li>You will not see your branch on gitlab until you push your branch.<br \/>\n\t<em>git push origin new_branch<\/em><\/li>\n<\/ol>\n<p><small>Get certification for your knowledge in the fundamentals of Computer functioning by clearing the Computer Certification exam conducted by StudySection. After going through this <a href=\"https:\/\/www.studysection.com\/computer-fundamentals-advanced\">Computer Certification<\/a> exam, you will be able to evaluate your basic knowledge of computers. <\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction to GIT Git is a content management and tracking system. It is a distributed revision control that is performed<\/p>\n","protected":false},"author":1,"featured_media":3138,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[159,519],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>StudySection Blog - Basic Commands Used in GIT<\/title>\n<meta name=\"description\" content=\"Git is a content management and tracking system. It is a distributed revision control that is performed on stored data. It is a SCM system.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/studysection.com\/blog\/git-basic-commands\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"StudySection Blog - Basic Commands Used in GIT\" \/>\n<meta property=\"og:description\" content=\"Git is a content management and tracking system. It is a distributed revision control that is performed on stored data. It is a SCM system.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/git-basic-commands\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Posts on famous people, innovations and educational topics\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/studysection\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-17T05:35:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-08-17T06:39:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2020\/08\/git.png\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin-studysection-blog\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@studysection\" \/>\n<meta name=\"twitter:site\" content=\"@studysection\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin-studysection-blog\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/git-basic-commands\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/git-basic-commands\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"GIT Basic Commands\",\"datePublished\":\"2020-08-17T05:35:02+00:00\",\"dateModified\":\"2020-08-17T06:39:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/git-basic-commands\/\"},\"wordCount\":755,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"Commands\",\"GIT\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/git-basic-commands\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/git-basic-commands\/\",\"url\":\"https:\/\/studysection.com\/blog\/git-basic-commands\/\",\"name\":\"StudySection Blog - Basic Commands Used in GIT\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2020-08-17T05:35:02+00:00\",\"dateModified\":\"2020-08-17T06:39:10+00:00\",\"description\":\"Git is a content management and tracking system. It is a distributed revision control that is performed on stored data. It is a SCM system.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/git-basic-commands\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/git-basic-commands\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/git-basic-commands\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"GIT Basic Commands\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/studysection.com\/blog\/#website\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"name\":\"Blog Posts on famous people, innovations and educational topics\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/studysection.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/studysection.com\/blog\/#organization\",\"name\":\"StudySection\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"contentUrl\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"width\":920,\"height\":440,\"caption\":\"StudySection\"},\"image\":{\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/studysection\",\"https:\/\/twitter.com\/studysection\",\"https:\/\/www.instagram.com\/study.section\/\",\"https:\/\/www.linkedin.com\/company\/studysection\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\",\"name\":\"admin-studysection-blog\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"caption\":\"admin-studysection-blog\"},\"url\":\"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"StudySection Blog - Basic Commands Used in GIT","description":"Git is a content management and tracking system. It is a distributed revision control that is performed on stored data. It is a SCM system.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/studysection.com\/blog\/git-basic-commands\/","og_locale":"en_US","og_type":"article","og_title":"StudySection Blog - Basic Commands Used in GIT","og_description":"Git is a content management and tracking system. It is a distributed revision control that is performed on stored data. It is a SCM system.","og_url":"https:\/\/studysection.com\/blog\/git-basic-commands\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2020-08-17T05:35:02+00:00","article_modified_time":"2020-08-17T06:39:10+00:00","og_image":[{"width":300,"height":200,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2020\/08\/git.png","type":"image\/png"}],"author":"admin-studysection-blog","twitter_card":"summary_large_image","twitter_creator":"@studysection","twitter_site":"@studysection","twitter_misc":{"Written by":"admin-studysection-blog","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/git-basic-commands\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/git-basic-commands\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"GIT Basic Commands","datePublished":"2020-08-17T05:35:02+00:00","dateModified":"2020-08-17T06:39:10+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/git-basic-commands\/"},"wordCount":755,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["Commands","GIT"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/git-basic-commands\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/git-basic-commands\/","url":"https:\/\/studysection.com\/blog\/git-basic-commands\/","name":"StudySection Blog - Basic Commands Used in GIT","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2020-08-17T05:35:02+00:00","dateModified":"2020-08-17T06:39:10+00:00","description":"Git is a content management and tracking system. It is a distributed revision control that is performed on stored data. It is a SCM system.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/git-basic-commands\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/git-basic-commands\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/git-basic-commands\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"GIT Basic Commands"}]},{"@type":"WebSite","@id":"https:\/\/studysection.com\/blog\/#website","url":"https:\/\/studysection.com\/blog\/","name":"Blog Posts on famous people, innovations and educational topics","description":"","publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/studysection.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/studysection.com\/blog\/#organization","name":"StudySection","url":"https:\/\/studysection.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","contentUrl":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","width":920,"height":440,"caption":"StudySection"},"image":{"@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/studysection","https:\/\/twitter.com\/studysection","https:\/\/www.instagram.com\/study.section\/","https:\/\/www.linkedin.com\/company\/studysection"]},{"@type":"Person","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402","name":"admin-studysection-blog","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","caption":"admin-studysection-blog"},"url":"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/"}]}},"views":686,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/3131"}],"collection":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/comments?post=3131"}],"version-history":[{"count":6,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/3131\/revisions"}],"predecessor-version":[{"id":3139,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/3131\/revisions\/3139"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/3138"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=3131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=3131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=3131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}