0

I recently switched to my master branch so I could get the latest updates. While in the 'master' branch I did some work and made changes that I would like to apply to a different feature branch. However, I don't want to commit these changes to the master branch yet. Is there a way with Git that I could apply these changes to a different feature branch without first committing them to the master branch. I also don't want to lose the changes.

webworm
  • 10,587
  • 33
  • 120
  • 217
  • Please read [ask] and try searching before asking a new question. You're looking to "stash" your changes. – CodeCaster Aug 15 '19 at 15:14
  • See also [moving changed files to another branch for check-in](https://stackoverflow.com/questions/7217894/moving-changed-files-to-another-branch-for-check-in) and many others. – CodeCaster Aug 15 '19 at 15:16

2 Answers2

2

git stash has you covered!

  1. While in the master branch, with the uncommitted files, run git stash.
  2. Switch to your feature branch
  3. Run git stash apply

git stash will save your uncommited changes into a "stash".

git stash apply will apply the latest stash.

If you have more than one stash, you can list them by running git stash list

Read more here: https://git-scm.com/docs/git-stash

MarvinJWendt
  • 2,357
  • 1
  • 10
  • 36
1

May not be the nicest way to do this, but I would commit the changes to master, but DON'T PUSH. Then switch to your feature branch and merge the changes into the feature branch. Then, switch back to master and checkout the previous commit that doesn't include the changes.

colleen
  • 43
  • 7