如何将git推送到一个还不存在的目的地

如何将git推送到一个还不存在的目的地,git,Git,我试图使用哈希在git服务器上创建一个新分支,但没有在本地创建分支: $ git push origin HEAD^:new-branch error: unable to push to unqualified destination: new-branch The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess

我试图使用哈希在git服务器上创建一个新分支,但没有在本地创建分支:

$ git push origin HEAD^:new-branch
error: unable to push to unqualified destination: new-branch
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.
error: failed to push some refs to 'git@github:company/repo.git'
当您强制推送现有分支时,此操作有效。我尝试过创建目标
refs/新分支
,它说:

$ git push origin HEAD^:refs/new-branch
Total 0 (delta 0), reused 0 (delta 0)
remote: error: refusing to create funny ref 'refs/new-branch' remotely
To github.com:company/repo.git
 ! [remote rejected]       HEAD^ -> refs/new-branch (funny refname)
error: failed to push some refs to 'git@github.com:company/repo.git'
还不存在的目的地的格式是什么

我打算这样做

$ git branch new-branch
$ git push origin new-branch
$ git push origin HEAD^:new-branch -f
$ git branch -D new-branch
$ git branch new-branch HEAD^
$ git push origin new-branch
$ git branch -D new-branch
还是像这样

$ git branch new-branch
$ git push origin new-branch
$ git push origin HEAD^:new-branch -f
$ git branch -D new-branch
$ git branch new-branch HEAD^
$ git push origin new-branch
$ git branch -D new-branch

但是需要知道如何在服务器上创建一个新分支,而不必在本地创建它

分支是
refs/heads/…
,而不仅仅是
refs/…
,因此您应该推到
refs/heads/new branch
在远程存储库上创建一个新分支

git push origin HEAD^:refs/heads/new-branch

分支是
refs/heads/…
,而不仅仅是
refs/…
,因此您应该点击
refs/heads/new branch
,在远程存储库上创建一个新分支

git push origin HEAD^:refs/heads/new-branch

你为什么要这么做?我认为GitHub web的界面允许直接在GitHub上创建真正的远程分支。我认为您正在寻找
--set upstream
标志。例如:
git push——设置上游原点[您的分支名称]
为什么要这样做?我认为GitHub web的界面允许直接在GitHub上创建真正的远程分支。我认为您正在寻找
--set upstream
标志。例如:
git push——设置上游原点[您的分支名称]