2

I have just done a "cherry picking" by executing

git fetch ssh://myname@something1 something2 && git checkout FETCH_HEAD

After I execute git branch (to see what branch I am in), I see that I am in a branch with a strange name: (HEAD detached at FETCH_HEAD):

* (HEAD detached at FETCH_HEAD)
  master

When I go to master by executing git checkout master this "strange" branch disappears and, as far as I understood, the changes that I "cherry picked" from the remote repository disappear as well (because they are in the "branch" that has disappeared).

So, my questions is: How can I merge the strange "branch" into the master so that the changes in this branch do not disappear?

Roman
  • 124,451
  • 167
  • 349
  • 456
  • You didn't cherry-pick anything at this point. the only thing you did was a branch hopping and nothing else. – ckruczek Nov 29 '17 at 14:35

1 Answers1

2

Create a new branch (say, b1) from FETCH_HEAD:

$ git fetch ssh://myname@something1 something2 && git checkout -b b1 FETCH_HEAD 

Push b1 branch to remote, then create Pull request or pull b1 into master directly.

$ git push origin b1

Pull b1 branch into master branch:

$ git checkout master
$ git pull origin b1    

Alternative: If you simply want the remote repo changes into local master branch then:

$ git fetch ssh://myname@something1 something2 && git checkout FETCH_HEAD

$ git checkout -b b1     # create b1 branch from FETCH_HEAD

$ git checkout master    # checkout to master
$ git merge b1           # merge b1 branch into master
Sajib Khan
  • 22,878
  • 9
  • 63
  • 73
  • Why do I need to push something to the remote branch? I just want to "take" something from the central repository. I do not contribute there at this point. – Roman Nov 29 '17 at 14:38