Moving Changes from Git Master to Branch in Eclipse

This post continues our series on using Git in Eclipse and will address moving code changes from a Git Master branch to the actual branch you had planned on using but had forgotten to checkout. This scenario is perfectly captured in this Julie Lerman tweet. Julie is a .NET Rock Star and a friend of mine, so it shows that even superstar developers encounter Git issues from time-to-time.

We started working on “Cool Feature Tuesday” when it dawns on us we’re in Master and wanted to be working in a branch. The Eclipse Package Explorer shows us in [master] with in a Git “dirty state” having been modified and not yet staged.

If you read through the many responses to Julie’s tweet you’ll see “stash” mentioned. That’s an option, but since we didn’t commit any changes all we have to do is create a new branch which will have our changes.

We complete the “Cool New Tuesday” changes.

We do a $ git add . then the sequence of Git commands below, where we’ll commit our changes, checkout master and merge it with our cool-new branch. Then we’ll push it upstream.

It’s important to note that when we checkout the master branch it was in its prior state with no changes, so we could have abandoned the cool-new branch or anything else to the branch and it would have had no effect on the project state in master.