1

Hi can you help me solve that problem? I am on a branch **(HEAD detached from refs/heads/master) where I have some new commits and I need add these changes into my master branch. an you tell me how to do that? Here is my output from terminal after entering git branch and git status **

denis@N56VJ:~/Workspace/ita-javaee-04$ git status
HEAD detached from refs/heads/master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        src/main/webapp/package-lock.json

nothing added to commit but untracked files present (use "git add" to track)
denis@N56VJ:~/Workspace/ita-javaee-04$ git branch
* (HEAD detached from refs/heads/master)
  master
denis@N56VJ:~/Workspace/ita-javaee-04$ 
9
  • 1
    Just create a branch with git checkout -b <new-branch-name>, and continue from there... Commented Nov 14, 2017 at 13:35
  • 1
    You can continue with master. Use git checkout -B master in this case.
    – Opal
    Commented Nov 14, 2017 at 13:48
  • 1
    Let me know if that worked.
    – Opal
    Commented Nov 14, 2017 at 13:51
  • 2
    @Opal git checkout -B master is dangerous, and should not be recommended to a git-newbie: It may loose commits at master! Commented Nov 14, 2017 at 13:54
  • 1
    @cmaster, you are absolutely right, I inferred that master is out of OP interest. Could have been wrong.
    – Opal
    Commented Nov 14, 2017 at 13:55

1 Answer 1

1

You could delete your old master and create a new one at your current HEAD.

git branch -D master
git checkout -b master
git branch --set-upstream-to=origin/master

If you're worried aboud making a mistake, then be sure to git show HEAD, git show master, and save the sha1 hashes as a backup. Alternatively, you can rely on git reflog.

Not the answer you're looking for? Browse other questions tagged or ask your own question.