{"id":54680,"date":"2022-02-02T10:16:39","date_gmt":"2022-02-02T04:46:39","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=54680"},"modified":"2022-02-02T10:16:39","modified_gmt":"2022-02-02T04:46:39","slug":"a-classic-mistake-faced-by-every-git-user","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/a-classic-mistake-faced-by-every-git-user\/","title":{"rendered":"A classic mistake faced by every git user"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Learning from mistakes will teach us a lifelong lesson, similarly here we are discussing a classic mistake that every git user made at least once i.e. committing code in the wrong branch.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you identify the mistake at the right time this can be easily managed, but it gets more tricky if you start committing code in the wrong branch. Let\u2019s take a problem statement to understand the issue more clearly.<\/span><\/p>\n<p><b>Problem Statement<\/b><\/p>\n<p><span style=\"font-weight: 400;\">You are working on a new feature and you forgot to change a new branch for it. You\u2019ve already done lots of work and committed in the master branch, now you\u2019ve realized you need to switch to a new feature branch keeping all work secure that you already committed in the master branch.<\/span><\/p>\n<p><b>Solution<\/b><\/p>\n<p><span style=\"font-weight: 400;\">git stash is the solution provided by git to prevent us from this mess. Follow the commands below to switch to the correct branch without losing your committed code.<\/span><\/p>\n<pre>$ git checkout new-feature<\/pre>\n<p><span style=\"font-weight: 400;\">If this succeeds, no need to worry, just commit your changes and push the changes in the new branch. In case the above command raises an error like the one below<\/span><\/p>\n<pre>error: Your local changes to the following files would be overwritten....<\/pre>\n<p><span style=\"font-weight: 400;\">Then execute the command below<\/span><\/p>\n<pre>$ git stash<\/pre>\n<p><span style=\"font-weight: 400;\">This command safely stores your changes in a local repository, and now you can switch your<\/span><span style=\"font-weight: 400;\"> branch without worries.<\/span><\/p>\n<pre>$ git checkout new-feature\r\n$ git stash apply<\/pre>\n<p><span style=\"font-weight: 400;\">Now you can see all your changes in the new feature branch. If everything goes well make sure to execute <\/span><em><span style=\"font-weight: 400;\">$<\/span><span style=\"font-weight: 400;\"> git stash drop<\/span><\/em><span style=\"font-weight: 400;\">, and it\u2019ll drop the reference of the branch created in your local repository.<\/span><\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>Learning from mistakes will teach us a lifelong lesson, similarly here we are discussing a classic mistake that every git user made at least once i.e. committing code in the wrong branch.\u00a0 If you identify the mistake at the right time this can be easily managed, but it gets more tricky if you start committing [&hellip;]<\/p>\n","protected":false},"author":1436,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":6,"footnotes":""},"categories":[1],"tags":[375],"class_list":["post-54680","post","type-post","status-publish","format-standard","hentry","category-technology","tag-git"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Learning from mistakes will teach us a lifelong lesson, similarly here we are discussing a classic mistake that every git user made at least once i.e. committing code in the wrong branch. If you identify the mistake at the right time this can be easily managed, but it gets more tricky if you start committing\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Harsh Vardhan Gupta\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/a-classic-mistake-faced-by-every-git-user\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"A classic mistake faced by every git user | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Learning from mistakes will teach us a lifelong lesson, similarly here we are discussing a classic mistake that every git user made at least once i.e. committing code in the wrong branch. If you identify the mistake at the right time this can be easily managed, but it gets more tricky if you start committing\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/a-classic-mistake-faced-by-every-git-user\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"A classic mistake faced by every git user | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Learning from mistakes will teach us a lifelong lesson, similarly here we are discussing a classic mistake that every git user made at least once i.e. committing code in the wrong branch. If you identify the mistake at the right time this can be easily managed, but it gets more tricky if you start committing\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-classic-mistake-faced-by-every-git-user\\\/#article\",\"name\":\"A classic mistake faced by every git user | TO THE NEW Blog\",\"headline\":\"A classic mistake faced by every git user\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/harsh-gupta\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2022-02-02T10:16:39+05:30\",\"dateModified\":\"2022-02-02T10:16:39+05:30\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-classic-mistake-faced-by-every-git-user\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-classic-mistake-faced-by-every-git-user\\\/#webpage\"},\"articleSection\":\"Technology, git\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-classic-mistake-faced-by-every-git-user\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"position\":2,\"name\":\"Technology\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-classic-mistake-faced-by-every-git-user\\\/#listItem\",\"name\":\"A classic mistake faced by every git user\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-classic-mistake-faced-by-every-git-user\\\/#listItem\",\"position\":3,\"name\":\"A classic mistake faced by every git user\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/harsh-gupta\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/harsh-gupta\\\/\",\"name\":\"Harsh Vardhan Gupta\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-classic-mistake-faced-by-every-git-user\\\/#authorImage\",\"url\":\"https:\\\/\\\/newersworld-sf-static.tothenew.net\\\/prod\\\/profilePicFolder\\\/60377d36-860d-4127-a6d6-7b767af98ebd_Harsh-Vardhan-Gupta-Profile-Pitcure.jpeg\",\"width\":96,\"height\":96,\"caption\":\"Harsh Vardhan Gupta\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-classic-mistake-faced-by-every-git-user\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-classic-mistake-faced-by-every-git-user\\\/\",\"name\":\"A classic mistake faced by every git user | TO THE NEW Blog\",\"description\":\"Learning from mistakes will teach us a lifelong lesson, similarly here we are discussing a classic mistake that every git user made at least once i.e. committing code in the wrong branch. If you identify the mistake at the right time this can be easily managed, but it gets more tricky if you start committing\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/a-classic-mistake-faced-by-every-git-user\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/harsh-gupta\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/harsh-gupta\\\/#author\"},\"datePublished\":\"2022-02-02T10:16:39+05:30\",\"dateModified\":\"2022-02-02T10:16:39+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"A classic mistake faced by every git user | TO THE NEW Blog","description":"Learning from mistakes will teach us a lifelong lesson, similarly here we are discussing a classic mistake that every git user made at least once i.e. committing code in the wrong branch. If you identify the mistake at the right time this can be easily managed, but it gets more tricky if you start committing","canonical_url":"https:\/\/www.tothenew.com\/blog\/a-classic-mistake-faced-by-every-git-user\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/a-classic-mistake-faced-by-every-git-user\/#article","name":"A classic mistake faced by every git user | TO THE NEW Blog","headline":"A classic mistake faced by every git user","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/harsh-gupta\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"datePublished":"2022-02-02T10:16:39+05:30","dateModified":"2022-02-02T10:16:39+05:30","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/a-classic-mistake-faced-by-every-git-user\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/a-classic-mistake-faced-by-every-git-user\/#webpage"},"articleSection":"Technology, git"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/a-classic-mistake-faced-by-every-git-user\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","name":"Technology"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","position":2,"name":"Technology","item":"https:\/\/www.tothenew.com\/blog\/category\/technology\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/a-classic-mistake-faced-by-every-git-user\/#listItem","name":"A classic mistake faced by every git user"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/a-classic-mistake-faced-by-every-git-user\/#listItem","position":3,"name":"A classic mistake faced by every git user","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","name":"Technology"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/harsh-gupta\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/harsh-gupta\/","name":"Harsh Vardhan Gupta","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/a-classic-mistake-faced-by-every-git-user\/#authorImage","url":"https:\/\/newersworld-sf-static.tothenew.net\/prod\/profilePicFolder\/60377d36-860d-4127-a6d6-7b767af98ebd_Harsh-Vardhan-Gupta-Profile-Pitcure.jpeg","width":96,"height":96,"caption":"Harsh Vardhan Gupta"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/a-classic-mistake-faced-by-every-git-user\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/a-classic-mistake-faced-by-every-git-user\/","name":"A classic mistake faced by every git user | TO THE NEW Blog","description":"Learning from mistakes will teach us a lifelong lesson, similarly here we are discussing a classic mistake that every git user made at least once i.e. committing code in the wrong branch. If you identify the mistake at the right time this can be easily managed, but it gets more tricky if you start committing","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/a-classic-mistake-faced-by-every-git-user\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/harsh-gupta\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/harsh-gupta\/#author"},"datePublished":"2022-02-02T10:16:39+05:30","dateModified":"2022-02-02T10:16:39+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"A classic mistake faced by every git user | TO THE NEW Blog","og:description":"Learning from mistakes will teach us a lifelong lesson, similarly here we are discussing a classic mistake that every git user made at least once i.e. committing code in the wrong branch. If you identify the mistake at the right time this can be easily managed, but it gets more tricky if you start committing","og:url":"https:\/\/www.tothenew.com\/blog\/a-classic-mistake-faced-by-every-git-user\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"A classic mistake faced by every git user | TO THE NEW Blog","twitter:description":"Learning from mistakes will teach us a lifelong lesson, similarly here we are discussing a classic mistake that every git user made at least once i.e. committing code in the wrong branch. If you identify the mistake at the right time this can be easily managed, but it gets more tricky if you start committing","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"54680","title":null,"description":null,"keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"#aioseo-article-65e059ab36113","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"limit_modified_date":false,"created":"2022-02-02 04:41:40","updated":"2024-02-29 10:17:15","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/technology\/\" title=\"Technology\">Technology<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tA classic mistake faced by every git user\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"Technology","link":"https:\/\/www.tothenew.com\/blog\/category\/technology\/"},{"label":"A classic mistake faced by every git user","link":"https:\/\/www.tothenew.com\/blog\/a-classic-mistake-faced-by-every-git-user\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/54680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1436"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=54680"}],"version-history":[{"count":2,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/54680\/revisions"}],"predecessor-version":[{"id":54682,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/54680\/revisions\/54682"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=54680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=54680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=54680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}