Skip to content

Instantly share code, notes, and snippets.

@iainsproat
Created January 12, 2014 00:11
Show Gist options
  • Save iainsproat/8378720 to your computer and use it in GitHub Desktop.
Save iainsproat/8378720 to your computer and use it in GitHub Desktop.
Git: stash work in progress and move it to a new branch
  • make changes
  • git stash save
  • git checkout -b xxx
  • git stash pop

where xxx is the new branch name

@xxxVxxx
Copy link

xxxVxxx commented Apr 14, 2019

But the moment i change the branch to master those files come back. Is it possible to only stash those changes to only that branch

@bernardoadc
Copy link

AFAIK, you don't need to stash changes. Commits only apply to the current branch. But there are exceptions, e.g. untracked files. Anyway git will let you know if any file would be lost when checking out

@xxxVxxx no, stashes are separate from branches, "floating" if you will. You can apply them anywhere, any branch, but always in the current branch (checkout to apply to other branches). You mean the files come back with old changes or the stashed changes?

@byaruhaf
Copy link

Thanks @bernardoadc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment