-->

gitolite: default remotes for new repository

2019-01-18 21:52发布

问题:

I've installed gitolite (locally for now, to experiment) and it seems to work, except that new repositories are not tracking the remote by default after a git clone. If I remember correctly, when I clone a repository from github.com, it's already able to push and pull.

Here is what I tried:

$ 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'

When I try to push explicitly everything works:

$ 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

Is this additional step really needed? Can be set by default? On github it is, isn't?

Thank you

回答1:

The first git push always require to specify the branch you want to push.

git push -u origin master

Then the next push can be done, from the same branch, as you intended:

git push

From git push man page:

The special refspec : (or +: to allow non-fast-forward updates) directs git to push "matching" branches: for every branch that exists on the local side, the remote side is updated if a branch of the same name already exists on the remote side.
This is the default operation mode if no explicit refspec is found.

Since you have cloned an empty repository, the first push doesn't find any matching branch (there is none on the upstream repo 'origin')

Note: See "What is the result of git push origin?":

The default policy for git push will change with git 2.0 (or maybe git1.9)

A new mode for push, "simple", which is a cross between "current" and "upstream", has been introduced.
"git push" without any refspec will push the current branch out to the same name at the remote repository only when it is set to track the branch with the same name over there.
The plan is to make this mode the new default value when push.default is not configured.

So in the git push -u origin master, the -u (--set-upstream-to) is important here (not just to push the branch with the same name to the remote 'origin', but it a remote tracking branch.



回答2:

You can use git branch --set-upstream command, eg.:
git branch --set-upstream develop origin/develop



标签: git gitolite