您能解释一下这个工作流程有什么问题吗?
$ 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'
git push
是否总是推送到我克隆的存储库?
答案 0 :(得分:473)
是的,问题是“裸露”没有提交。如果您按顺序创建repos(bare,alice),这只是第一次提交的问题。尝试做:
git push --set-upstream origin master
这只是第一次需要。之后它应该正常工作。
正如Chris Johnsen指出的那样,如果你的push.default是自定义的,你就不会有这个问题。我喜欢上游/跟踪。
答案 1 :(得分:43)
如果你:
git push origin master
它将推向裸机库。
听起来你的alice repo没有正确跟踪。
cat .git/config
这将显示默认的远程和分支。
如果你
git push -u origin master
您应该开始跟踪该远程和分支。我不确定这个选项是否总是在git中。
答案 2 :(得分:28)
这个相关问题的答案为我提供了解决方案......这只是一个愚蠢的错误:
记得先提交!
https://stackoverflow.com/a/7572252
如果您尚未提交本地仓库,则无需推送,但您收到的Git错误消息对您没有多大帮助。
答案 3 :(得分:17)
git push --all
是将所有内容推送到新裸存储库的规范方法。
另一种做同样事情的方法是创建新的非裸存储库,然后使用
进行裸克隆git clone --bare
然后使用
git remote add origin <new-remote-repo>
在原始(非裸)存储库中。
答案 4 :(得分:7)
在alice
存储库(推送前)中尝试此操作:
git config push.default tracking
或者,使用git config --global …
将其配置为您的用户的默认设置。
git push
默认为origin
存储库(通常是您从中克隆当前存储库的存储库),但它不默认推送当前分支 - 它默认只推送分支存在于源存储库和目标存储库中。
push.default
配置变量(参见git-config(1))控制git push
在未给出任何“refspec”参数(即存储库名称后面的内容)时将推送的内容。默认值给出了上述行为。
以下是push.default
的可能值:
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 分支。
matching
设置会在您的方案中建立后更新bare
的主。要建立它,您可以使用git push origin master
一次。
但是,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
(同样,如果您在1.7.4.2之前仍在使用Git,则需要使用tracking
代替upstream
)。
答案 5 :(得分:1)
我使用 SourceTree git客户端,我看到他们的初始提交/推送命令是:
git -c diff.mnemonicprefix=false -c core.quotepath=false push -v --tags --set-upstream origin master:master