问题描述
|
您能解释一下此工作流程有什么问题吗?
$ 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\'
ѭ1不会总是推送到我从中克隆的存储库吗?
解决方法
是的,问题在于\“ bare \”中没有提交。如果您按顺序(裸机,驴友)创建存储库,那么这仅是第一次提交的问题。尝试做:
git push --set-upstream origin master
仅在第一次时才需要。之后,它应该可以正常工作。
正如Chris Johnsen指出的那样,如果push.default是自定义的,则不会出现此问题。我喜欢上游/跟踪。
, 如果你:
git push origin master
它会推送到裸仓库。
听起来您的爱丽丝仓库未正确跟踪。
cat .git/config
这将显示默认的远程和分支。
如果你
git push -u origin master
您应该开始跟踪该遥控器和分支机构。我不确定该选项是否一直在git中。
, 这个相关问题的答案为我提供了解决方案……这只是一个愚蠢的错误:
请记住先提交!
https://stackoverflow.com/a/7572252
如果您尚未提交本地存储库,则无需执行任何操作,但是您收到的Git错误消息并不能给您太大帮助。
, git push --all
是将所有内容推送到新的裸存储库的规范方法。
另一种执行相同操作的方法是创建新的非裸存储库,然后使用
git clone --bare
然后使用
git remote add origin <new-remote-repo>
在原始(非裸露)存储库中。
, 在您的“ 9”存储库中尝试此操作(在推送之前):
git config push.default tracking
或者,使用git config --global …
将其配置为用户的默认设置。
git push
确实默认为origin
信息库(通常是您从中克隆当前信息库的信息库),但默认情况下不推送当前分支-默认为仅推送源信息库和目标信息库中都存在的分支。
push.default
配置变量(请参见git-config(1))控制controls1ѭ在未提供任何“ 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分支。
scenario18ѭ设置一旦建立便会更新scenario30ѭ的母版。要建立它,可以一次使用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客户端,看到它们的初始commit / push命令是:
git -c diff.mnemonicprefix=false -c core.quotepath=false push -v --tags --set-upstream origin master:master