Search code examples
gitcherry-pickgit-fetch

How to merge the result of a fetch into the master?


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?


Solution

  • 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