1

Is it possible to push the checked-out history (a detached HEAD) to a remote branch, without having a local branch checked-out?

In case I need a corresponding local branch, I can checkout the remote one locally, later on. I do not need to track it; and I don't want to use a tag.

I tried git push my_remote HEAD:my_remotebranch_name but git tells me:

error: unable to push to unqualified destination: my_remotebranch_name The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess a prefix based on the source ref.

How do I achieve it?

Kamafeather
  • 8,663
  • 14
  • 69
  • 99
  • You need to be on some branch in the current repository in order to be able to push (exception: if you are pushing for the first time to an empty repo, nothing needs to exist remotely, but even in this case, you would still be on some branch). – Tim Biegeleisen Feb 27 '20 at 05:10
  • https://stackoverflow.com/search?q=%5Bgit%5D+error%3A+unable+to+push+to+unqualified+destination – phd Feb 27 '20 at 05:20
  • `git push my_remote HEAD:refs/heads/my_remotebranch_name` – phd Feb 27 '20 at 05:21
  • @phd thank your for finding it out! Great! You can add an answer so I can accept it (tomorrow?), or you can vote for duplicate (but I think the title of the question here is more clear about the use case than the question you linked). – Kamafeather Feb 27 '20 at 05:40
  • 1
    @Kamafeather I've already voted for dup. – phd Feb 27 '20 at 05:42

2 Answers2

1

The solution was to use a fully-qualified-name for the remote branch, to remove ambiguity and not make git try to guess.

git push my_remote HEAD:refs/heads/my_remotebranch_name

This will work event if HEAD is in a detached state (that was my case).

Thank you @phd.

Kamafeather
  • 8,663
  • 14
  • 69
  • 99
0

I am not sure if I understood your question perfectly. This is what I understand: You want to push changes on your local git head to a remote branch, without actually creating a new branch on your local.

I tried doing that. I pulled a repo, made some changes and ran: git push origin master:dummy and also git push origin HEAD:dummy2

And it works fine. It creates a new branch in your remote repo and pushes the changes to there.

Pradipta Sarma
  • 1,142
  • 10
  • 17