Git: Oops! I didn’t mean to commit on that remote tracking branch!


I’ve talked about 2 very similar situations in the past. This is just a small variation, but I still find it useful enough to make another small post. I’m using the same checkout and reset commands that I’ve shown before. The small difference here, is that I’m using a remote branch as a point of reference in the reset calls. This let’s me move my local branch that is tracking the remote back to the same commit as the remote.

Committing To The Wrong Branch

In the first screen shot, you can see that the master branch is ahead of the origin/master remote branch.

Screen shot 2011 02 23 at 10 34 43 AM

Creating A Topic Branch

The first thing I need to do is create a new branch that points to the same commit as master.

Screen shot 2011 02 23 at 10 35 22 AM

Now you can see the new branch pointing to the same commit as master.

Screen shot 2011 02 23 at 10 35 39 AM

Resetting Master

Here, I’m using git reset to move the master branch to a different commit. In this case, I’m moving back to the same commit as the origin/master remote branch.

Screen shot 2011 02 23 at 10 36 43 AM

And now my repository looks the way I want. I have master and origin/master tracking nicely, and I have a topic branch that contains all of the work I had been doing.

Screen shot 2011 02 23 at 10 37 00 AM

Hiding Sensitive Information With A Base64 Encoded Dictionary And Binary Serialization