2

I have local git branch <BRANCH_NAME> that has no reference to upstream origin. I have made some changes to local branch and committed the same locally. I am now trying to push to remote origin.

  1. When I tried: git push --set-upstream origin <BRANCH_NAME> it throws the error :
error:src refsprc <LOCAL_BRANHC_NAME> does not match any 
error: failed to push some refs to '<REMOTE_URL>
  1. When i tried git push --set-upstream origin **HEAD:**<BRANCH_NAME> it succeeded

The difference between the commands is the prefixing of HEAD: to the "BRANCH_NAME". So my question is :

  1. What's difference between pushing with/without the prefix "HEAD" ?
  2. Would be helpful if I can get pictorial representation of what's happening behind the git commands for my better understanding.
  3. Let me know if more information is required from my end for clarification.

NOTE:

  • I do understand what is HEAD. It points to the latest commit of the current branch.
  • I did try the cat .git/HEAD and the output was ref: refs/heads/<BRANCH_NAME> - which is the correct one.
  • I noted in some answers of stackoverflow, it was mentioned to do git commit . I had tried the commit approach as well and faced the same error.

Thanks in advance

Sriram
  • 53
  • 7

1 Answers1

0

Check the ouput of a git status: you won't be in a detached HEAD mode, but you can see if you have untracked files that could be added/committed (as I mentioned here).

Check also the output of git branch -avv to see both local and remote branches.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • thanks for your reply. 1. I did check out the "git commit" related answers. As I have mentioned, I did "git commit" locally and then only tried the "git push". 2. For ```git branch -avv```, since it is new local branch, there is no upstream for – Sriram May 09 '20 at 02:07
  • @Sriram Can you add the list of branches (and tags if you have some) to the question, just to check for anyhting peculiar in that list? (`git branch -l`, `git tag -l`) – VonC May 09 '20 at 15:33