Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge (no branch) into master

dave@dave-dev:/media/dev/belgravia$ git branch
* (no branch)
  master

I'm not sure how this happened, but is there a way I can merge no-branch into the master. I'm not sure how I can merge two branches when one of them is not a branch. The commits in no-branch seem to be loose. I'm afraid that checkout master will cause data loss.

like image 944
Keyo Avatar asked Jan 13 '11 00:01

Keyo


People also ask

Can I merge to master without pull request?

It looks like GitHub only allows merging of branches by making a pull request and then merging. Is there a way to merge mobile into master in a single step without cloning locally? There's no way without using a pull request.


3 Answers

Use git show to get the SHA1 commit ID of the current HEAD. With that information, you can't lose those commits.

Then, switch to master and:

git merge abc123

where abc123 is the SHA1 from the first step.

like image 87
Greg Hewgill Avatar answered Oct 14 '22 01:10

Greg Hewgill


Maybe you can commit it on current branch(no-branch)

Then you have to do:

git reflog

After that you can get the id of this commit like 1d84d08

do:

git checkout master 
git merge 1d84d08
like image 41
Justin_lu Avatar answered Oct 14 '22 03:10

Justin_lu


The reason you have (no branch) is you have done:

git checkout REMOTE_BRANCH_NAME
  • In order for you to work locally on that branch you have to do: git checkout -b local_branch_new_name
  • now do a: git branch - a
  • you will see:

local_branch_new_name

  master
  • From here you can merge a branch into master the usual way. switch to master and do:

    git merge local_branch_new_name

like image 36
venkat Avatar answered Oct 14 '22 01:10

venkat