How to keep your local changes and switch to another branch in Git?

Sometime you forgot change your Git branch before do something with your codes and now you have to apply the recently changes to another branch. So, perform the following steps to handle this:

Step 1 In current branch (branch contains your local changes) run command:

 $ git stash

Step 2 Switch to branch that you'd like to apply your local changes:

 $ git checkout another_branch

Step 3 Apply your local changes to another_branch with the command:

 $ git stash apply

Now, another_branch has had your local changes.

Happy with Git!!

© 2019 4codev

Created with love by Sil.