gitolite:新存储库的默认遥控器

sti*_*vlo 15 git gitolite

我已经安装了gitolite(现在是本地的,用于实验),它似乎有效,除了新的存储库在git clone之后没有默认跟踪远程.如果我没记错的话,当我从github.com克隆一个存储库时,它已经能够推送.

这是我尝试过的:

$ git clone git@localhost:sandbox
Cloning into sandbox...
warning: You appear to have cloned an empty repository.
$ echo "A" > README
$ git add README
$ git commit README -m 'test'
$ 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 'git@localhost:sandbox'
Run Code Online (Sandbox Code Playgroud)

当我尝试明确推送一切正常时:

$ git push origin master
Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 426 bytes, done.
Total 6 (delta 0), reused 0 (delta 0)
To git@localhost:sandbox
 * [new branch]      master -> master
Run Code Online (Sandbox Code Playgroud)

这个额外步骤真的需要吗?可以默认设置吗?在github上,不是吗?

谢谢

Von*_*onC 23

第一个git push总是需要指定要推送的分支.

git push -u origin master
Run Code Online (Sandbox Code Playgroud)

然后可以按照您的意图从同一分支完成下一次推送:

git push
Run Code Online (Sandbox Code Playgroud)

git push手册页:

特殊refspec :(或+:允许非快进更新)指示git推送"匹配"分支:对于本地端存在的每个分支,如果远程端上已存在同名分支,则更新远程端侧.
如果未找到显式refspec,则这是默认操作模式.

由于你克隆了一个空的存储库,第一次推送没有找到任何匹配的分支(上游repo'上origin没有)

注意:请参阅" 结果是git push origin什么? ":

git push的默认策略将随git 2.0(或git1.9)而改变

推出了一种新的推送模式," simple"是" current"和" upstream" 之间的交叉.
" git push"没有任何refspec,只有当它被设置为跟踪那里具有相同名称的分支时,才会将当前分支推送到远程存储库中的相同名称.
计划是在push.default未配置时将此模式设为新的默认值.

所以在这里git push -u origin master,-u(--set-upstream-to)在这里很重要(不仅仅是将具有相同名称的分支推送到远程' origin',而是一个远程跟踪分支.