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

后端 未结 2 1242
小鲜肉
小鲜肉 2020-12-31 19:06

Our goal is to do internal development based on a project hosted on an external repo (github) using git and gerrit. We would pull from the external repo periodically to brin

相关标签:
2条回答
  • 2020-12-31 19:26

    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.

    0 讨论(0)
  • 2020-12-31 19:29

    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/*
    
    0 讨论(0)
提交回复
热议问题