0

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

Dims
  • 47,675
  • 117
  • 331
  • 600

1 Answers1

3

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.

Graham
  • 7,431
  • 18
  • 59
  • 84
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • What is the purpose of second `git checkout master`? I will still be on `master` after `git fetch`, won't I? – Dims Sep 01 '16 at 11:31
  • I tried to make the steps as independent as possible, to minimize the chance that you might go wrong. Yes, if you do both steps back-to-back then the second `git checkout master` is redundant and can be skipped. – Tim Biegeleisen Sep 01 '16 at 11:33
  • What will happen with my files on disk after `git reset --hard origin/master`? Will they be replaced with files from server from commit `origin/master`? – Dims Sep 01 '16 at 11:38
  • Of course, the local files will reflect the local branch, which at that point will be whatever the state of `origin/master` was when you reset to it. – Tim Biegeleisen Sep 01 '16 at 11:44