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.
Creating A Topic Branch
The first thing I need to do is create a new branch that points to the same commit as master.
Now you can see the new branch pointing to the same commit as 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.
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.