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?

Answers


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

How to place todo reminders in Dreamweaver code

dreamweaver bookmarks reminders todos

I am coding in Dreamweaver for a change. Is there a way to place reminders in your code, for example in the form of a "todo list"?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.