Getting local gerrit and repository working (including branches) based on a github project

人走茶凉 提交于 2019-11-30 09:40:15

When you perform a git push, it only pushes the active branch (HEAD). If you wish to push all branches and tags, do something like git push origin refs/heads/* --tags

It isn't technically required to have a local copy of the repository before pushing to Gerrit, but it is probably the easiest method.

MartyMacGyver

I believe I've found the answer for myself. It boils down to how you create the repository (and is my formal introduction to bare repos).

In short, you can clone a repo the default way:

git clone https://github.com/foobar/myrepo.git

Which yields a local clone with working directory myrepo, within which is the myrepo/.git directory tree.

Or you can clone it bare. There are a couple of ways to do this, but the --mirror option appears to yields the most complete replica:

git clone --mirror https://github.com/foobar/myrepo.git

This produces the myrepo.git directory (as one might see in gerrit or in gitolite) which has the same structure as the myrepo/.git directory above, but without the working directory bits.

Note: I'll add that I'm not sure now whether a mirror is preferable to a bare clone with remote refs for the branches... I've got another thread going that inquires about this. For completeness, then, here's a way to create a bare clone with remote refs (the key being no working directory):

git init --bare ${LOCAL_REPO}
cd ${LOCAL_REPO}
git remote add origin ${REMOTE_URL}
git fetch origin --tags
git fetch origin

I tested the mirror idea as a one-off, cloning a repo straight into the local gerrit installation folder where All-Projects.git also lives, restarted gerrit and it sees the repo as well as all its branches. However, it's not the ideal way for gerrit. You should instead push from a local clone (preferably a bare one).

So in gerrit, create a new empty project via the web admin interface (I didn't put an initial empty commit into it - not sure if that would cause problems), then from within a local mirror of the repo you're trying to replicate, push it to the new, empty gerrit repo along with the branches and tags:

git push <gerrit_repo> refs/heads/* refs/tags/*
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!