Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitolite: default remotes for new repository

Tags:

git

gitolite

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

like image 271
stivlo Avatar asked Jun 30 '11 01:06

stivlo


People also ask

How do I create a Gitolite repository?

To add a new repo, you have to clone the gitolite-admin repository, then edit the conf/gitolite. conf file. In that file, add the repo, along with at least one user with some permissions.

What is a remote repository URL?

A remote URL is Git's fancy way of saying "the place where your code is stored." That URL could be your repository on GitHub, or another user's fork, or even on a completely different server. You can only push to two types of URL addresses: An HTTPS URL like https://github.com/user/repo.git.


1 Answers

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.

like image 180
VonC Avatar answered Oct 07 '22 19:10

VonC