简体   繁体   中英

Understanding : git push --set-upstream “refspec” with and without prefixing “HEAD”

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM