Moving from one branch to another without committing changes

I believe this is what git stash is for, but want to confirm...

I'm working on a couple of topic branches from master. I occasionally need to jump back and forth between them (master included) and pull the latest from our remote, make some changes, then jump back to the other branch.

If I've worked on file that's shared between branches, I can't simply run git checkout <branch> to move between them. I'm told I must add & commit my changes first. I'd prefer not to do that sometimes and was wondering about good ways to go about moving from branch to branch as independently as possible, committing only when desired?


Yes, that's what stash is for. It adds and commits the index and working tree to a new commit and merge commit. Then you have a clean working tree, and you can cleanly checkout any other branch to work on. Then on any branch - not just the one where you stashed it - you can git stash pop to move that stash back into the work tree and index, and drop the stash. Usually you would head back to the original branch and pop there to continue where you left off, but sometimes it's helpful to be able to stash and move elsewhere to avoid a conflict, which stash might be able to circumvent.

Definitely read up on it (git help stash) - there are other options, such as working on only the work tree or index, or adding a message to it so it's easy to remember why you made the stash later, etc.

Need Your Help

Cleaning a Production Database for use in Testing

mysql database virtualbox sanitization

I'm building a local vm for doing web dev rather than using our on site development. I need a database locally, but I don't want to just pull down a production db and use that as it has information...

Old JavaScript Function Crashes Browser

javascript mootools

I'm integrating a mootools script onto a page which has very old JavaScript functions which run a navigation vertical menu. This old script will be hard to change now.