git 为什么我不能推送到这个裸存储库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6157730/
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
Why can't I push to this bare repository?
提问by ripper234
Can you explain what is wrong with this workflow?
你能解释一下这个工作流程有什么问题吗?
$ git init --bare bare
Initialized empty Git repository in /work/fun/git_experiments/bare/
$ git clone bare alice
Cloning into alice...
done.
warning: You appear to have cloned an empty repository.
$ cd alice/
$ touch a
$ git add a
$ git commit -m "Added a"
[master (root-commit) 70d52d4] Added a
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a
$ git push
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '/work/fun/git_experiments/bare'
Doesn't git push
always push to the repository I cloned from?
并不git push
总是推送到我从中克隆的存储库?
回答by Seth Robertson
Yes, the problem is that there are no commits in "bare". This is a problem with the first commit only, if you create the repos in the order (bare,alice). Try doing:
是的,问题在于“裸”中没有提交。如果您按顺序 (bare,alice) 创建存储库,这仅是第一次提交的问题。尝试做:
git push --set-upstream origin master
This would only be required the first time. Afterwards it should work normally.
这仅在第一次需要。之后它应该可以正常工作。
As Chris Johnsen pointed out, you would not have this problem if your push.default was customized. I like upstream/tracking.
正如 Chris Johnsen 指出的那样,如果您的 push.default 是自定义的,您就不会遇到这个问题。我喜欢上游/跟踪。
回答by serby
If you:
如果你:
git push origin master
it will push to the bare repo.
它将推送到裸仓库。
It sounds like your alice repo isn't tracking correctly.
听起来您的 alice 存储库没有正确跟踪。
cat .git/config
This will show the default remote and branch.
这将显示默认的远程和分支。
If you
如果你
git push -u origin master
You should start tracking that remote and branch. I'm not sure if that option has always been in git.
您应该开始跟踪该远程和分支。我不确定该选项是否一直存在于 git 中。
回答by phpguru
This related question's answer provided the solution for me... it was just a dumb mistake:
这个相关问题的答案为我提供了解决方案......这只是一个愚蠢的错误:
Remember to commit first!
记得先提交!
https://stackoverflow.com/a/7572252
https://stackoverflow.com/a/7572252
If you have not yet committed to your local repo, there is nothing to push, but the Git error message you get back doesn't help you too much.
如果您还没有提交到您的本地存储库,则没有什么可推送的,但是您返回的 Git 错误消息对您没有太大帮助。
回答by ebneter
git push --all
is the canonical way to push everything to a new bare repository.
是将所有内容推送到新裸存储库的规范方式。
Another way to do the same thing is to create your new, non-bare repository and then make a bare clone with
做同样事情的另一种方法是创建新的非裸存储库,然后使用
git clone --bare
then use
然后使用
git remote add origin <new-remote-repo>
in the original (non-bare) repository.
在原始(非裸)存储库中。
回答by Chris Johnsen
Try this in your alice
repository (before pushing):
在您的alice
存储库中尝试此操作(推送之前):
git config push.default tracking
Or, configure it as the default for your user with git config --global …
.
或者,使用git config --global …
.
git push
does default to the origin
repository (which is normally the repository from which you cloned the current repository), but it does not default to pushing the current branch—it defaults to pushing only branches that exist in both the source repository and the destination repository.
git push
确实默认到origin
存储库(通常是您从中克隆当前存储库的存储库),但它不默认推送当前分支——它默认只推送同时存在于源存储库和目标存储库中的分支。
The push.default
configuration variable (see git-config(1)) controls what git push
will push when it is not given any “refspec” arguments (i.e. something after a repository name). The default value gives the behavior described above.
该push.default
配置变量(见的git-配置(1) )控制什么git push
时候(存储库名称后,即东西)没有给出任何“的Refspec”参数将推动。默认值给出了上述行为。
Here are possible values for push.default
:
以下是 的可能值push.default
:
nothing
This forces you to supply a “refspec”.matching
(the default)
This pushes allbranches that exist in both the source repository and the destination repository.
This is completely independent of the branch that is currently checked out.upstream
ortracking
(Both values mean the same thing. The later was deprecated to avoid confusion with “remote-tracking” branches. The former was introduced in 1.7.4.2, so you will have to use the latter if you are using Git 1.7.3.1.)
These push the current branch to the branch specified by its “upstream” configuration.current
This pushes the current branch to the branch of the same name at the destination repository.These last two end up being the same for common cases (e.g. working on local masterwhich uses origin/masteras its upstream), but they are different when the local branch has a different name from its “upstream” branch:
git checkout master # hack, commit, hack, commit # bug report comes in, we want a fix on master without the above commits git checkout -b quickfix origin/master # "upstream" is master on origin # fix, commit git push
With
push.default
equal toupstream
(ortracking
), the push would go toorigin
's masterbranch. When it is equal tocurrent
, the push would go toorigin
's quickfixbranch.
nothing
这迫使您提供“refspec”。matching
(默认)
这会推送源存储库和目标存储库中存在的所有分支。
这完全独立于当前检出的分支。upstream
或tracking
(两个值的含义相同。不推荐使用后者以避免与“远程跟踪”分支混淆。前者是在 1.7.4.2 中引入的,因此如果您使用的是 Git 1.7.3.1,则必须使用后者。 )
这些将当前分支推送到由其“上游”配置指定的分支。current
这会将当前分支推送到目标存储库中的同名分支。对于常见情况,最后两个最终是相同的(例如,在使用origin/master作为其上游的本地master上工作),但是当本地分支与其“上游”分支具有不同的名称时,它们是不同的:
git checkout master # hack, commit, hack, commit # bug report comes in, we want a fix on master without the above commits git checkout -b quickfix origin/master # "upstream" is master on origin # fix, commit git push
随着
push.default
等于upstream
(或tracking
),推送会去origin
的主分支。当它等于 时current
,推送将转到origin
的quickfix分支。
The matching
setting will update bare
's masterin your scenario once it has been established. To establish it, you could use git push origin master
once.
一旦建立,该matching
设置将更新您场景中bare
的master。要建立它,您可以使用git push origin master
一次。
However, the upstream
setting (or maybe current
) seems like it might be a better match for what you expect to happen, so you might want to try it:
但是,upstream
设置(或可能current
)似乎更符合您期望发生的情况,因此您可能想尝试一下:
# try it once (in Git 1.7.2 and later)
git -c push.default=upstream push
# configure it for only this repository
git config push.default upstream
# configure it for all repositories that do not override it themselves
git config --global push.default upstream
(Again, if you are still using a Git before 1.7.4.2, you will need to use tracking
instead of upstream
).
(同样,如果您仍在使用 1.7.4.2 之前的 Git,则需要使用tracking
代替upstream
)。
回答by IgorGanapolsky
I use SourceTreegit client, and I see that their initial commit/push command is:
我使用SourceTreegit 客户端,我看到他们的初始提交/推送命令是:
git -c diff.mnemonicprefix=false -c core.quotepath=false push -v --tags --set-upstream origin master:master