Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (29.3k points)

How can I do the following in Git?

My current branch is branch1 and I have made some local changes. However, I now realize that I actually meant to be applying these changes to branch2. Is there a way to apply/merge these changes so that they become local changes on branch2 without committing them on branch1?

1 Answer

0 votes
by (50.2k points)

Since your files are not committed in the branch so you can use the following commands:

git stash

git checkout branch2

git stash pop

Or you can use 

git stash

git checkout branch2

git stash list       # to check the various stash made in a different branch

git stash apply x    # to select the right one

And to stash currently untracked (newly added) files:

git stash -u


Browse Categories