为什么我不能推到这个裸仓库?
你能解释这个工作stream程有什么问题吗?
$ 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到我从克隆的存储库? 
是的,问题是没有“裸”的提交。 如果您按顺序创build仓库(裸设备,alice),则仅第一次提交时就会出现问题。 尝试做:
 git push --set-upstream origin master 
这只是第一次需要。 之后它应该正常工作。
正如克里斯·约翰森指出,如果你的push.default是自定义的,你不会有这个问题。 我喜欢上游/跟踪。
如果你:
  git push origin master 
它会推到裸露的回购。
这听起来像你的爱丽丝回购没有正确跟踪。
 cat .git/config 
这将显示默认的远程和分支。
如果你
  git push -u origin master 
你应该开始跟踪那个远程和分支。 我不确定这个选项是否一直在git中。
这个相关的问题的答案为我提供了解决scheme…这只是一个愚蠢的错误:
记得首先提交!
https://stackoverflow.com/a/7572252
如果你还没有承诺到你的本地回购,没有什么可推动的,但你回来的Git错误信息并不能帮你太多。
 git push --all 
是推动一切到一个新的裸仓库的规范的方式。
另一种做同样的事情的方法是创build你的新的,非裸存储库,然后做一个裸露的克隆
 git clone --bare 
然后使用
 git remote add origin <new-remote-repo> 
在原始(非裸)存储库中。
 试试这个在你的alice存储库(推之前): 
 git config push.default tracking 
 或者,使用git config --global …将其configuration为用户的默认值。 
  git push默认为origin资源库(通常是克隆当前资源库的资源库),但它并不默认推送当前分支 – 它默认只推送源资源库和目标中存在的分支库。 
  push.defaultconfigurationvariables(请参阅git-config(1) )控制当没有给定任何“refspec”参数(即存储库名称后的某个参数)时, git push将推送的内容。 默认值给出了上面描述的行为。 
 以下是push.default可能值: 
- 
nothing
 这迫使你提供一个“refspec”。
- 
matching(默认)
 这将推送源存储库和目标存储库中存在的所有分支。
 这完全独立于当前检出的分支。
- 
upstream或tracking
 (这两个值意思是一样的,为避免与“远程跟踪”分支混淆,后者被弃用,前者是在1.7.4.2中引入的,因此如果使用Git 1.7.3.1,则必须使用后者。
 这些将当前分支推送到由其“上游”configuration指定的分支。
- 
current
 这会将当前分支推送到目标存储库中同名的分支。最后的两个结果在常见情况下是相同的(例如,在使用origin / 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分支。
 一旦build立, matching设置将在您的scheme中更新bare的主设备 。 要build立它,你可以使用一次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 )。 
我使用SourceTree git客户端,我看到他们的初始提交/推送命令是:
 git -c diff.mnemonicprefix=false -c core.quotepath=false push -v --tags --set-upstream origin master:master