0

It happens that in a branch where I was making code fixes by mistake I started to make some changes (modify and create files) that corresponded to another branch. How could you pass some specific files from one branch to another? Thank you!

1 Answers1

0

The simplest way would be to stash the changes, move to the correct branch, and apply the stashed changes. Please note that stash defaults to the push subcommand, so git stash and git stash push are equivalent.

git stash [<pathspec>...] # store the changes in the current tree
git switch <correct_branch>  # move to the proper branch (use checkout if git < 2.23)

# apply the changes to the correct branch
git stash apply
git stash drop

You could combine the last two lines into git stash pop, the only difference being that the stash is automatically dropped and if you need to use it again for some reason, you will have lost access to it.

joshmeranda
  • 3,001
  • 2
  • 10
  • 24