Search code examples
gitworkflowgit-branchgit-pushgit-remote

Push HEAD to remote branch, without having a local branch


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?


Solution

  • 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.