Setting up new project in Gerrit
Because Gerrit is evil and wrong (see here for details), even such simple task,like creating a new project, requires a separate document and todo list. Also, keep in mind, that you can’t delete a project through web GUI of Gerrit. This is most wanted and requested feature of this dully project management tool, but still hasn’t been implemented for years. So, create your new project wisely, because you won’t be able to delete them, without playing around console, installing some third-party plugins or doing stupidities similar to this.
Piece of crap!
You may notice, that this article is full of bad words and even hate-speach. That is correct and intended. I hate Gerrit and I’m pretty pissed off every day, I’m forced to use it, by my manager. I hate Gerrit, because it is a whole big piece of crap, created by moron, over which many other morons are jerking off each day, fouling normal freaks, that this piece of shit is usable. It isn’t. And yes — I’m pretty sure, that Gerrit is created by moron. Because, only a complete moron could create a project management system without implementing project deletion feature in it!
Okay, enough of shit. Let’s focus on topic. Why it is painful? Because, construction of Gerrit causes, that you can’t clone an empty repository (
warning: remote HEAD refers to nonexistent ref, unable to checkout). Just like that. Something, that is obvious around GitHub or many, many other version control and project management systems is yet another thing wasted in Gerrit. You have to do all the stuff manually.
Don’t you EVER, NEVER check the
Create initial empty commit option, when creating new project in Gerrit! This is another wasted feature in this dully piece of crap. If you select it, Gerrit will create new project without
refs/meta/config branch, rendering it virtually unusable.
…are always the same, no matter, which method you’re going to choose and use later:
1. Begin with creating new project in Gerrit UI, by visiting an URL similar to this:
2. Now, visit
Project > Access, edit rights (if you have sufficient privileges) and add user or group, which you use, to be able to access this project.
3. Open console. Navigate to your projects directory, create new folder (i.e.
mkdir gerrit-is-fucked) and navigate into it (
4. Go to
Project > General and click URL presented there to copy only URL (without
git clone command part). It should be something like
ssh://[USER]@[URL]:29418/[PROJECT] (always use SSH-type URL and SSH keys to avoid constant entering of your login and password).
The GitHub way
This one is fastest and most secure, therefore recommended one. You can use GitHub instructions. Those, you see, when you create a new repository there. This is the “bottom-to-up” way, which assumes, that you’re biding your new Gerrit project with your local repository, by making push:
git add README.md
git commit -m "Inital commit."
git remote add origin ssh://[USER]@[URL]:29418/[PROJECT]
git push -u origin master
Only remember to adjust things to your need, like properly changing URL, adding different file, changing initial commit’s message or doing whatever you wish.
The other way
This one is an alternative one, which does not always work. You can also use this way, if you wish, if — for example you don’t like the GitHub way presented next. This is the “up-to-bottom” way, which assumes, that you’re biding your new Gerrit project with your local repository, by making pull.
1. Initialize new, empty git repository inside (
2. Add above mentioned URL as remote to your newly created git repository (
git remote add origin ssh://[USE]R@[URL]:29418/[PROJECT]).
3. Even though your new project’s repository should be empty, it actually isn’t. Gerrit keeps some internal shit inside and thus,
git push fails. You need to do
git pull origin master first. This should end up with
Merge made by the 'recursive' strategy. message. Question, what we’re actually merging, since remote repository should be empty, can be only answered by morons, who created Gerrit.
4. Set upstream tracking branch for your local repository (
git push --set-upstream origin master) to avoid specyfing of remote and branch on each next push or pull. Confirm with login and password (the one found in
Settings > HTTP Password section), if requested to do so.
Last steps are also the same for both ways:
commit-msg hook. Copy it from another repository’s
.git/hooks folder or install (details here).
git config remote.origin.push HEAD:refs/for/master command to set proper refs for each
You can skip first point, if you have ever copied this hook to
c:Program Files (x86)Gitsharegit-coretemplateshooks. Because, in this case each new repository will be created (
git init) with proper hook in place.
Actually, you should read-through [Git+Gerrit workflow for modern projects](http://onezeronull.com/2014/11/21/gitgerrit-workflow-for-modern-projects/] article, if you’re unfamiliar with it, because it contains some interesting tips to fight the Gerrit horror.