0 votes
1 view
in DevOps and Agile by (30k 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 (51.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

Reference: https://git-scm.com/docs/git-stash#_options

Welcome to Intellipaat Community. Get your technical queries answered by top developers !