{"id":540,"date":"2015-11-28T07:05:55","date_gmt":"2015-11-28T07:05:55","guid":{"rendered":"http:\/\/shabeebk.com\/blog\/?p=540"},"modified":"2022-03-29T13:57:27","modified_gmt":"2022-03-29T13:57:27","slug":"common-git-commands","status":"publish","type":"post","link":"http:\/\/shabeebk.com\/blog\/common-git-commands\/","title":{"rendered":"Common git commands"},"content":{"rendered":"\n<p>Here is a list of commonly used git commands<\/p>\n\n\n\n<ul><li>Initiate a directory as git<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git init --bare<\/pre>\n\n\n\n<ul><li>Git clone<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git clone url-to-git\n\nexample URL :user@domain.com:\/home-path\/username\/directory\/<\/pre>\n\n\n\n<ul><li>Git&nbsp;status<\/li><\/ul>\n\n\n\n<p>it will show the files status &#8211; modified, tracking , untracked<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">git status<\/pre>\n\n\n\n<ul><li>Git Add for tracking<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git add filename\nor \ngit add .\ndot is using to add all files<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/affiliates.hostgator.in\/affiliate.php?id=8062_0_1_16\" target=\"_blank\" rel=\"noopener\"><img class=\"lazy \" src=\"http:\/\/shabeebk.com\/blog\/wp-content\/plugins\/jquery-image-lazy-loading\/images\/grey.gif\" data-original=\"http:\/\/affiliates.hostgator.in\/media\/banners\/234x60B.gif\" alt=\"\"\/><noscript><img src=\"http:\/\/affiliates.hostgator.in\/media\/banners\/234x60B.gif\" alt=\"\"\/><\/noscript><\/a><\/figure>\n\n\n\n<ul><li>Git commit<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git commit -m \"commit message\"<\/pre>\n\n\n\n<p>If the file is under git track we can combine both comments in one line like<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">git commit -am \"your-message\"\nor\ngit  commit -a -m \"your-message\"\n\n-a to add\n-m to commit message<\/pre>\n\n\n\n<ul><li>Push your changes to server<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git push\n\nor \ngit push branch<\/pre>\n\n\n\n<ul><li>Creating &nbsp;branch in git<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git branch  branch-name \n<\/pre>\n\n\n\n<ul><li>Switch to branch<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git checkout branch-name<\/pre>\n\n\n\n<ul><li>Create a new branch and switch to new branch<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git checkout -b branch name<\/pre>\n\n\n\n<ul><li>List all the branches<\/li><\/ul>\n\n\n\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-1812723430816589\"\n     crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\"\n     style=\"display:block; text-align:center;\"\n     data-ad-layout=\"in-article\"\n     data-ad-format=\"fluid\"\n     data-ad-client=\"ca-pub-1812723430816589\"\n     data-ad-slot=\"9698274892\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<pre class=\"wp-block-preformatted\">git branch -a<\/pre>\n\n\n\n<ul><li>Merge Branch<\/li><\/ul>\n\n\n\n<p>Consider we have master branch A and another branch B,<\/p>\n\n\n\n<p>To merge branch B changes to branch A,<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">git checkout branch A\ngit merge branch B\n<\/pre>\n\n\n\n<p>if any conflict happened, it will show conflict, we have to do modification and commit again.<\/p>\n\n\n\n<ul><li>Delete a branch<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git branch -d &lt;brach name&gt;<\/pre>\n\n\n\n<p>this will delete if all the changes are merged, if you want to use force delete , even not merged,<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">git branch -D &lt;branch name&gt;<\/pre>\n\n\n\n<ul><li>Upload branch into server at setting head for push<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git push --set-upstream origin &lt;branch name&gt;<\/pre>\n\n\n\n<ul><li>Stash all local changes<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git stash<\/pre>\n\n\n\n<ul><li>Take back stashed changes &#8211; This will take aback all the changes you stashed<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git stash pop<\/pre>\n\n\n\n<ul><li>Discard changes on one file<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git checkout filename<\/pre>\n\n\n\n<ul><li>Remove local commit&nbsp;&nbsp;and reset to server head &#8211; &nbsp;it will delete all the local changes<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git reset --hard origin\/branch name<\/pre>\n\n\n\n<ul><li>List all the branches push\/pull remote origin.<\/li><\/ul>\n\n\n\n<p>This will show all the remote and local branches and where it is pointing into<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">git remote show origin<\/pre>\n\n\n\n<ul><li>Fetch and push origin list<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git remote  -v<\/pre>\n\n\n\n<ul><li>View uncommitted changes made<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"> git diff<\/pre>\n\n\n\n<ul><li>To see all the logs<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git log<\/pre>\n\n\n\n<ul><li>To see log with difference<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git log -p<\/pre>\n\n\n\n<ul><li>Git log for a single file<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">git log -p file\/path\n-p will give changes also<\/pre>\n\n\n\n<ul><li>Other options with git log<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"> git log --stat    \/\/this will show only number of files changed and number of changes\ngit log --pretty=oneline    \/\/show all the changes in one line with head and comment\ngit log --pretty=format:\"%h - %an, %ar : %s\"   \/\/show with name time and commit message\n\ngit log --author=username  \/\/show only one user commit<\/pre>\n\n\n\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-1812723430816589\"\n     crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\"\n     style=\"display:block; text-align:center;\"\n     data-ad-layout=\"in-article\"\n     data-ad-format=\"fluid\"\n     data-ad-client=\"ca-pub-1812723430816589\"\n     data-ad-slot=\"9698274892\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n<div class=\"pvc_clear\"><\/div><p class=\"pvc_stats all \" data-element-id=\"540\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;16,615&nbsp;total views, &nbsp;1&nbsp;views today<\/p><div class=\"pvc_clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Here is a list of commonly used git commands Initiate a directory as git git init &#8211;bare Git clone git clone url-to-git example URL :user@domain.com:\/home-path\/username\/directory\/ Git&nbsp;status it will show the files status &#8211; modified, tracking , untracked git status Git Add for tracking git add filename or git add . dot is using to add [&hellip;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"540\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;16,615&nbsp;total views, &nbsp;1&nbsp;views today<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[3,1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.4.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Common git commands - shabeeb Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/shabeebk.com\/blog\/common-git-commands\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Common git commands - shabeeb Blog\" \/>\n<meta property=\"og:description\" content=\"Here is a list of commonly used git commands Initiate a directory as git git init --bare Git clone git clone url-to-git example URL :user@domain.com:\/home-path\/username\/directory\/ Git&nbsp;status it will show the files status &#8211; modified, tracking , untracked git status Git Add for tracking git add filename or git add . dot is using to add &hellip;\" \/>\n<meta property=\"og:url\" content=\"http:\/\/shabeebk.com\/blog\/common-git-commands\/\" \/>\n<meta property=\"og:site_name\" content=\"shabeeb Blog\" \/>\n<meta property=\"article:published_time\" content=\"2015-11-28T07:05:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-29T13:57:27+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/affiliates.hostgator.in\/media\/banners\/234x60B.gif\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"shabeeb\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"http:\/\/shabeebk.com\/blog\/#website\",\"url\":\"http:\/\/shabeebk.com\/blog\/\",\"name\":\"shabeeb Blog\",\"description\":\"A developer blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/shabeebk.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"http:\/\/shabeebk.com\/blog\/common-git-commands\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/affiliates.hostgator.in\/media\/banners\/234x60B.gif\",\"contentUrl\":\"http:\/\/affiliates.hostgator.in\/media\/banners\/234x60B.gif\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/shabeebk.com\/blog\/common-git-commands\/#webpage\",\"url\":\"http:\/\/shabeebk.com\/blog\/common-git-commands\/\",\"name\":\"Common git commands - shabeeb Blog\",\"isPartOf\":{\"@id\":\"http:\/\/shabeebk.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/shabeebk.com\/blog\/common-git-commands\/#primaryimage\"},\"datePublished\":\"2015-11-28T07:05:55+00:00\",\"dateModified\":\"2022-03-29T13:57:27+00:00\",\"author\":{\"@id\":\"http:\/\/shabeebk.com\/blog\/#\/schema\/person\/71832abe654179971635c65c09bceb29\"},\"breadcrumb\":{\"@id\":\"http:\/\/shabeebk.com\/blog\/common-git-commands\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/shabeebk.com\/blog\/common-git-commands\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/shabeebk.com\/blog\/common-git-commands\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/shabeebk.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Common git commands\"}]},{\"@type\":\"Person\",\"@id\":\"http:\/\/shabeebk.com\/blog\/#\/schema\/person\/71832abe654179971635c65c09bceb29\",\"name\":\"shabeeb\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"http:\/\/shabeebk.com\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/0.gravatar.com\/avatar\/9998389cc76a77663881c48f7d4cbba0?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/0.gravatar.com\/avatar\/9998389cc76a77663881c48f7d4cbba0?s=96&d=mm&r=g\",\"caption\":\"shabeeb\"},\"description\":\"Developer,Entrepreneur, software engineer more than that a human being\",\"sameAs\":[\"http:\/\/shabeebk.com\/blog\"],\"url\":\"http:\/\/shabeebk.com\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Common git commands - shabeeb Blog","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":"http:\/\/shabeebk.com\/blog\/common-git-commands\/","og_locale":"en_US","og_type":"article","og_title":"Common git commands - shabeeb Blog","og_description":"Here is a list of commonly used git commands Initiate a directory as git git init --bare Git clone git clone url-to-git example URL :user@domain.com:\/home-path\/username\/directory\/ Git&nbsp;status it will show the files status &#8211; modified, tracking , untracked git status Git Add for tracking git add filename or git add . dot is using to add &hellip;","og_url":"http:\/\/shabeebk.com\/blog\/common-git-commands\/","og_site_name":"shabeeb Blog","article_published_time":"2015-11-28T07:05:55+00:00","article_modified_time":"2022-03-29T13:57:27+00:00","og_image":[{"url":"http:\/\/affiliates.hostgator.in\/media\/banners\/234x60B.gif"}],"twitter_misc":{"Written by":"shabeeb","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"http:\/\/shabeebk.com\/blog\/#website","url":"http:\/\/shabeebk.com\/blog\/","name":"shabeeb Blog","description":"A developer blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/shabeebk.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"http:\/\/shabeebk.com\/blog\/common-git-commands\/#primaryimage","inLanguage":"en-US","url":"http:\/\/affiliates.hostgator.in\/media\/banners\/234x60B.gif","contentUrl":"http:\/\/affiliates.hostgator.in\/media\/banners\/234x60B.gif"},{"@type":"WebPage","@id":"http:\/\/shabeebk.com\/blog\/common-git-commands\/#webpage","url":"http:\/\/shabeebk.com\/blog\/common-git-commands\/","name":"Common git commands - shabeeb Blog","isPartOf":{"@id":"http:\/\/shabeebk.com\/blog\/#website"},"primaryImageOfPage":{"@id":"http:\/\/shabeebk.com\/blog\/common-git-commands\/#primaryimage"},"datePublished":"2015-11-28T07:05:55+00:00","dateModified":"2022-03-29T13:57:27+00:00","author":{"@id":"http:\/\/shabeebk.com\/blog\/#\/schema\/person\/71832abe654179971635c65c09bceb29"},"breadcrumb":{"@id":"http:\/\/shabeebk.com\/blog\/common-git-commands\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/shabeebk.com\/blog\/common-git-commands\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/shabeebk.com\/blog\/common-git-commands\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/shabeebk.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Common git commands"}]},{"@type":"Person","@id":"http:\/\/shabeebk.com\/blog\/#\/schema\/person\/71832abe654179971635c65c09bceb29","name":"shabeeb","image":{"@type":"ImageObject","@id":"http:\/\/shabeebk.com\/blog\/#personlogo","inLanguage":"en-US","url":"http:\/\/0.gravatar.com\/avatar\/9998389cc76a77663881c48f7d4cbba0?s=96&d=mm&r=g","contentUrl":"http:\/\/0.gravatar.com\/avatar\/9998389cc76a77663881c48f7d4cbba0?s=96&d=mm&r=g","caption":"shabeeb"},"description":"Developer,Entrepreneur, software engineer more than that a human being","sameAs":["http:\/\/shabeebk.com\/blog"],"url":"http:\/\/shabeebk.com\/blog\/author\/admin\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/posts\/540"}],"collection":[{"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/comments?post=540"}],"version-history":[{"count":13,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/posts\/540\/revisions"}],"predecessor-version":[{"id":645,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/posts\/540\/revisions\/645"}],"wp:attachment":[{"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/media?parent=540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/categories?post=540"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/tags?post=540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}