In this post we’re going to walk through the 3.2 Git Branching – Basic Branching and Merging section of Pro Git. In the Pro Git example we’re working on an issue (Issue 53, to be precise) when a call comes in to apply a hot fix to the main application source tree. Our main objective is to see what the checkouts, branching and merging involved in this task look like in Eclipse.
Working on Issue 53
Our Project is up-to-date with the repository as you can see in the Package Manager below. Egit icons show all files are tracked and known to the repository.
We’ll begin working on Issue 53 by creating and checking out a new branch called iss53.
When we make a change to our GitTempWork.java file EGit shows us that the resource is “dirty”, or has changes that are neither in the index nor in the repository.
We Get The Call
We’re ready to knock out Issue 53, but we get the call informing us that we need to apply a hot fix to the main application source tree. We don’t want to include the Issue 53 code in the hot fix so we commit the work we’ve done in our iss53 branch and checkout master where, if we were to view our Eclipse Package Explorer, would be identical to what it looked like before we started work on Issue 53.
We’ve applied our hot fix. We’ll now commit the hot fix update, checkout master, merge the hotfix branch with master, then push it to the repository. (The push doesn’t seem to be included in the screenshot, but it happened…)
Back to Issue 53
We can now get back to Issue 53, but what about the hot-fix updates? Here’s a helpful excerpt from the Pro Git guide on the state of the two branches, master and iss53.
It’s worth noting here that the work you did in your hotfix branch is not contained in the files in your iss53 branch. If you need to pull it in, you can merge your master branch into your iss53 branch by running git merge master, or you can wait to integrate those changes until you decide to pull the iss53 branch back into master later.
We’re going to go ahead and merge the hot fix updates into our Issue 53 code before getting back to work.
Uh-oh! A Merge conflict!
Truth be told, both hotfix and iss53 updated the same line of code for this demo.
EGit shows us in a Merge Conflicted State.
We resolve our conflict with the following code.
Resolution and Updating the Repository
With our merge conflict resolved, we’ll finish working on Issue 53 and are now ready to commit. Here is the sequence of commands we’ll use.
Our git status shows that we’re in a conflict state, but we’ve resolved that and have completed Issue 53. So we’ll do a commit in our iss53 branch, then merge master with it, at which point we’ll push to the repository.
To prove that everything worked as planned and that our source contains both the hot fix update and Issue 53 we’ll check what’s in the repo.
Be sure to read through this section of Pro Git online for all of the details.