Dims Dims - 3 months ago 10
Git Question

How to move "master" label to some point in the past in Git?

I was designing my application and at some point realized, that what I am doing is a separate branch. I was committing my changes into local repository into "master", but not into remote repository.

In my VCS log in IntelliJ I see the following picture:

enter image description here

I.e. I have two separates paths of development with me and remote.

The

HEAD
position indicates, that I have already checked out to position, where I wish
master
be located.

How would I put master here? What is the name of this operation? Merge? Rebase? Or What?

I want to leave my branch as
AsyncIntegrate
and let master me synchronized with
origin/master
. I am not ready to merge these parallel lines.

UPDATE

Sorry, finally I wish to move
master
to where
origin/master
is:

enter image description here

I was thinking this should be done in 2 steps.

UPDATE 2

Will it be correct if I invoke the following command from IntelliJ:

enter image description here

Answer

This sounds like you want to shift your current working branch into a new branch called AsyncIntegrate and then reset your local master to origin/master.

Create the feature branch:

git checkout master
git checkout -b AsyncIntegrate

Reset your local master to origin/master:

git fetch
git checkout master
git reset --hard origin/master

The git fetch step above is important and should not be ignored, because it will update your local tracking branch origin/master with the current state of affairs of the actual remote master branch. If for some reason you want to use the (possibly stale) origin/master, then you can omit this step.

Update:

Take a deep breath and relax, because there is little chance for something catastrophic to happen here. All the work you (perhaps incorrectly) did on the local master branch should now be safe in a new local branch called AsyncIntegrate. And your local master would simply be in sync with the state of the remote, which is usually where you want to be.

And even if you were to loose the previous commit you were working on, you could always recover it from the Reflog. Resetting branches is succinctly mentioned in the documentation

Comments