{"id":426597,"date":"2022-04-05T00:00:00","date_gmt":"2022-04-04T21:00:00","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-stash-changes-in-git\/"},"modified":"2022-04-05T00:00:00","modified_gmt":"2022-04-04T21:00:00","slug":"how-to-stash-changes-in-git","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-stash-changes-in-git\/","title":{"rendered":"#How to Stash Changes in Git"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a38493f4fb03\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a38493f4fb03\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-stash-changes-in-git\/#%E2%80%9CHow_to_Stash_Changes_in_Git%E2%80%9D\" >&#8220;How to Stash Changes in Git&#8221;<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-stash-changes-in-git\/#Why_Stash_Your_Changes\" >Why Stash Your Changes?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-stash-changes-in-git\/#How_to_Stash_Changes\" >How to Stash Changes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-stash-changes-in-git\/#View_Stashed_Changes\" >View Stashed Changes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-stash-changes-in-git\/#Retrieve_Stashed_Changes\" >Retrieve Stashed Changes<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E2%80%9CHow_to_Stash_Changes_in_Git%E2%80%9D\"><\/span>&#8220;How to Stash Changes in Git&#8221;<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<div>\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage alignnone size-full wp-image-759896\" data-pagespeed-lazy-srcset=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/10\/git-logo-blue-background.jpg?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/10\/git-logo-blue-background.jpg?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/10\/git-logo-blue-background.jpg?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Git logo on a blue background\" width=\"1200\" height=\"675\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Need to switch to a different branch, but you\u2019re not ready to commit the changes you\u2019ve made in your current branch? You can stash your changes and come back to them later. It\u2019s possible in Git, whether you use GitHub or another hosting service.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Why_Stash_Your_Changes\"><\/span>Why Stash Your Changes?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Stashing your changes is a great way to keep up with your current work without committing them to the working branch. This allows you to work between several branches without pushing any changes.<\/p>\n<p>There are several cases in which you may need to stash your changes. Let\u2019s say, for example, that you\u2019re working on branch A. However, there\u2019s a serious bug in the code of branch B that needs your im<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">media<\/a>te attention. You need to switch over to branch B to fix the bug, but you\u2019re not ready to commit the work you\u2019ve been doing in branch A.<\/p>\n<p>Thanks to git stash, you can stash your changes in branch A without pushing them, switch over and fix the bug in branch B, and then switch back to branch A and pick up where you left off.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"How_to_Stash_Changes\"><\/span><a rel=\"nofollow noopener\" target=\"_blank\" name=\"autotoc_anchor_1\">How to Stash Changes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can stash your changes by running a simple command. Before doing that, though, you can run a different command to see exactly what you\u2019ll be stashing. In your working branch, run this command:<\/p>\n<pre>git status<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-789785\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/03\/Run-the-git-status-command..png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Run the git status command.\" width=\"644\" height=\"196\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>This will show you both the staged and unstaged changes you\u2019ve made in your branch. In our case, we\u2019ve modified the \u201ctest.md\u201d file. Keep in mind that git stash will stash both staged and unstaged changes.<\/p>\n<p>Now that you\u2019ve reviewed what will be stashed, run this command to stash the changes:<\/p>\n<pre>git stash<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-789786\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/03\/Run-the-git-stash-command..png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Run the git stash command.\" width=\"630\" height=\"207\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Once executed, you\u2019ll then receive a message stating that your changes have been stashed on &lt;branch-name&gt;.\u00a0 Your branch will now look like it did before you made your changes, and it\u2019s now safe to switch over to a new branch.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"View_Stashed_Changes\"><\/span><a rel=\"nofollow noopener\" target=\"_blank\" name=\"autotoc_anchor_2\">View Stashed Changes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you\u2019ve saved several stashes, you may want to see a list of the stashes before you try to retrieve one. When you view a list of your stashes, take note of the name of the stash you want to retrieve and continue working on.<\/p>\n<p>In the terminal, run this command:<\/p>\n<pre>git stash list<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-789788\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/03\/Run-git-stash-list-command..png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Run git stash list command.\" width=\"629\" height=\"275\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>A list of stashes will then be returned. In the example above, our stash name is <code>stash@{0}<\/code>. The number inside the curly brackets is the index. If you have several stashes on the same branch, the number will be different.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-789789\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/03\/An-example-of-a-stash-with-different-numbers..png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"An example of a stash with different numbers.\" width=\"635\" height=\"265\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If you want to view the details of a stash, run:<\/p>\n<pre>git stash show<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-789790\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/03\/Run-the-git-stash-show-command..png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Run the git stash show command.\" width=\"631\" height=\"225\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You can also run <code>git stash show -p<\/code> to view the results in diff format.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Retrieve_Stashed_Changes\"><\/span><a rel=\"nofollow noopener\" target=\"_blank\" name=\"autotoc_anchor_3\">Retrieve Stashed Changes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Once you\u2019re ready to pick up where you left off, you\u2019ll need to retrieve your stashed changes. There are two different ways you can do this. One command will keep a copy of your changes in the stash while also copying it over to your working branch. The other will copy everything over to your working branch, but will remove everything from the stash.<\/p>\n<p>To keep a copy of your changes in the stash and also bring them over to your working branch, run:<\/p>\n<pre>git stash apply<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-789792\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/03\/run-git-stash-apply-command..png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"run git stash apply command.\" width=\"642\" height=\"323\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>To bring the changes to your working branch but delete the copy of the stash, run:<\/p>\n<pre>git stash pop<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-789793\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/03\/Run-the-git-stash-pop-command..png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Run the git stash pop command.\" width=\"643\" height=\"336\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If there are multiple stashes on a single branch, simply add the name of the stash to the end of the command.<\/p>\n<p>You can now continue working with your previous changes. Once you\u2019ve made all the necessary changes to the branch and have merged it to the main branch, don\u2019t forget to <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.howtogeek.com\/753133\/how-to-delete-a-branch-on-github\/\">delete the branch to keep your repository clean!<\/p>\n<p><strong>RELATED:<\/strong> <strong><em>How to Delete a Branch on GitHub<\/em><\/strong><\/p>\n<\/div>\n<p><script>\n setTimeout(function(){\n  !function(f,b,e,v,n,t,s)\n  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?\n  n.callMethod.apply(n,arguments):n.queue.push(arguments)};\n  if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';\n  n.queue=[];t=b.createElement(e);t.async=!0;\n  t.src=v;s=b.getElementsByTagName(e)[0];\n  s.parentNode.insertBefore(t,s) } (window, document,'script',\n  'https:\/\/connect.facebook.net\/en_US\/fbevents.js');\n   fbq('init', '335401813750447');\n   fbq('track', 'PageView');\n  },3000);\n<\/script><\/p>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.howtogeek.com\/777899\/how-to-stash-changes-in-git\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;How to Stash Changes in Git&#8221; Need to switch to a different branch, but you\u2019re not ready to commit the changes you\u2019ve made in your current branch? You can stash your changes and come back to them later. It\u2019s possible in Git, whether you use GitHub or another hosting service. Why Stash Your Changes? Stashing&#8230;<\/p>\n","protected":false},"author":1,"featured_media":426598,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/10\/git-logo-blue-background.jpg?height=200p&trim=2,2,2,2","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-426597","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/426597","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=426597"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/426597\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/426598"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=426597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=426597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=426597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}