git:为空项目推送一个新的空分支?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27201656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:36:01  来源:igfitidea点击:

git: pushing a new, empty branch for an empty project?

gitbitbucket

提问by yayu

I have an empty project on remote, which I cloned. Now I want to start working on a branch, testdevand start working on it without putting any code to master.

我在远程有一个空项目,我克隆了它。现在我想开始在一个分支上工作,testdev并开始在不将任何代码交给 master 的情况下进行工作。

$ git checkout -b testdev
$ git status
On branch testdev

Initial commit

nothing to commit (create/copy files and use "git add" to track)

Now I try to push this branch to bitbucket

现在我尝试将此分支推送到 bitbucket

$ git push origin testdev

error: src refspec testdev does not match any.
error: failed to push some refs to 'https://[email protected]/myremoterepo.git'

I tried git add .and git commit -m "msg"but that is useless as I don't have any files to track or commit. So how do I push an empty branch to an empty project?

我试过了git add .git commit -m "msg"但这是无用的,因为我没有任何要跟踪或提交的文件。那么如何将一个空分支推送到一个空项目呢?

回答by VonC

If you repo is still empty, you might try and create an empty commit, to have somethingto push:

如果你的 repo 仍然是空的,你可以尝试创建一个空的提交,来推送一些东西

git commit --allow-empty -m "initial commit"
git push -u origin testdev

See also "Why do I need to explicitly push a new branch?".

另请参阅“为什么我需要明确推送一个新分支?”。