<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Manish Rana</title>
    <description>The latest articles on Forem by Manish Rana (@manishrana).</description>
    <link>https://forem.com/manishrana</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F87989%2F9a6b8fa2-0d4e-4e5a-b891-430b1087f312.jpeg</url>
      <title>Forem: Manish Rana</title>
      <link>https://forem.com/manishrana</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/manishrana"/>
    <language>en</language>
    <item>
      <title>Apply changes from one branch to a newer branch created from MAIN or MASTER branch using GIT STASH</title>
      <dc:creator>Manish Rana</dc:creator>
      <pubDate>Wed, 21 Dec 2022 03:20:38 +0000</pubDate>
      <link>https://forem.com/manishrana/apply-changes-from-one-branch-to-another-new-branch-created-from-main-or-master-branch-using-git-stash-52lo</link>
      <guid>https://forem.com/manishrana/apply-changes-from-one-branch-to-another-new-branch-created-from-main-or-master-branch-using-git-stash-52lo</guid>
      <description>&lt;p&gt;CASE: We sometimes tend to forget to checkout to a newer clean branch created from the master branch (yes, I did that) and make changes in the same branch which we currently are. Then we suddenly realize the new changes must be in the newer branch (yes, I did realize that when I made that mistake). For that, we have GIT STASH to the rescue.&lt;/p&gt;

&lt;p&gt;As we can see in this case we might not know that when we use GIT STASH the changes can be applied to any branch we have created in the project.&lt;/p&gt;

&lt;p&gt;I normally would tend to GIT STASH the changes in the current branch that I was working on so I could go to another branch with bugs to be fixed. Then I would come back to the current working branch and GIT STASH APPLY to apply the changes that were stashed.&lt;/p&gt;

&lt;p&gt;But as for the CASE explained above we can also apply the changes to the newer branch created from another branch. Generally, we create a new fresh branch from a branch that is deployed to the server and stable.&lt;/p&gt;

&lt;p&gt;Suppose we are in a branch &lt;code&gt;feature/payment&lt;/code&gt; and we need to make changes in the newer branch &lt;code&gt;feature/billing&lt;/code&gt; which we might be required to create from &lt;code&gt;master&lt;/code&gt; or &lt;code&gt;main&lt;/code&gt; or any other stable branch.&lt;/p&gt;

&lt;p&gt;Note: When using GIT STASH remember that the changes from the last commit are stashed. So, if the changes required for feature/payment are already committed, only the newer changes will be stashed. Otherwise, the changes made for the feature/payment will also be stashed. Then, when you do GIT STASH APPLY, all the changes will be applied until the last commit (which we don't want).&lt;br&gt;
Please learn about GIT STASH for more.&lt;/p&gt;

&lt;p&gt;For that we can do as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash 
//changes on the feature/payment branch i.e. current branch are stashed

git checkout main      
//checking out to the main or master or any other stable branch

git checkout -b feature/billing  
//creating a newer branch from the 'main'  branch and checking out to that branch

git stash apply
//apply the latest stash to the current branch i.e.
feature/billing which has changes stashed from feature/payment
the branch which should be in the feature/billing branch

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>git</category>
      <category>gitstash</category>
    </item>
  </channel>
</rss>
