{"id":3438,"date":"2015-01-20T01:23:06","date_gmt":"2015-01-20T00:23:06","guid":{"rendered":"http:\/\/glandium.org\/blog\/?page_id=3438"},"modified":"2015-02-11T08:08:51","modified_gmt":"2015-02-11T07:08:51","slug":"a-git-workflow-for-gecko-development","status":"publish","type":"page","link":"https:\/\/glandium.org\/blog\/?page_id=3438","title":{"rendered":"A git workflow for Gecko development"},"content":{"rendered":"<p>Here is my recommended setup for Gecko development with git:<\/p>\n<ul>\n<li>Install mercurial (only needed for its libraries). You probably already have it installed. Eventually, this dependency will go away, because the use of mercurial libraries is pretty limited.<\/li>\n<li>Use git 2.2.2 or newer, or rebuild an older git with this patch applied: <a href=\"https:\/\/github.com\/git\/git\/commit\/61e704e38a4c3e181403a766c5cf28814e4102e4\">https:\/\/github.com\/git\/git\/commit\/61e704e38a4c3e181403a766c5cf28814e4102e4<\/a>. It will make small fetches and pushes much faster.<\/li>\n<li>Install <a href=\"https:\/\/github.com\/glandium\/git-cinnabar\">git-cinnabar<\/a>. Just clone it somewhere, and put that directory in your <code>PATH<\/code>.<\/li>\n<li>Create a git repository for Mozilla code:<br \/>\n<blockquote>\n<pre>$ git init gecko\r\n$ cd gecko<\/pre>\n<\/blockquote>\n<\/li>\n<li>Set <code>fetch.prune<\/code> for git-cinnabar to be happier:<br \/>\n<blockquote>\n<pre>$ git config fetch.prune true<\/pre>\n<\/blockquote>\n<\/li>\n<li>Set <code>push.default<\/code> to \"upstream\", which I think allows a better workflow to use topic branches and push them more easily:<br \/>\n<blockquote>\n<pre>$ git config push.default upstream<\/pre>\n<\/blockquote>\n<\/li>\n<li>Add remotes for the mercurial repositories you pull from:<br \/>\n<blockquote>\n<pre>$ git remote add central hg::https:\/\/hg.mozilla.org\/mozilla-central -t branches\/default\/tip\r\n$ git remote add inbound hg::https:\/\/hg.mozilla.org\/integration\/mozilla-inbound -t branches\/default\/tip\r\n$ git remote set-url --push inbound hg::ssh:\/\/hg.mozilla.org\/integration\/mozilla-inbound\r\n(...)\r\n<\/pre>\n<\/blockquote>\n<p><code>-t branches\/default\/tip<\/code> is there to reduce the amount of churn from the old branches on these repositories.<br \/>\nIf you want access to all the branch tips, my recommended setting is the following:<\/p>\n<blockquote>\n<pre>$ git config remote.central.fetch +refs\/heads\/branches\/*\/tip:refs\/remotes\/central\/*\r\n$ git config remote.inbound.fetch +refs\/heads\/branches\/*\/tip:refs\/remotes\/inbound\/*\r\n<\/pre>\n<\/blockquote>\n<p>This exposes the branch tips as <code>refs\/remotes\/$remote\/$branch<\/code> instead of <code>refs\/remotes\/$remote\/branches\/$branch\/tip<\/code>.<br \/>\nYou can use a similar setup without the wildcards if you want the remote branch names to be shorter, such as:<\/p>\n<blockquote>\n<pre>$ git config remote.central.fetch +refs\/heads\/branches\/default\/tip:refs\/remotes\/central\/default\r\n$ git config remote.inbound.fetch +refs\/heads\/branches\/default\/tip:refs\/remotes\/inbound\/default\r\n<\/pre>\n<\/blockquote>\n<p>This exposes the tip of the default branch as <code>refs\/remotes\/$remote\/default<\/code> instead of <code>refs\/remotes\/$remote\/branches\/default\/tip<\/code>.\n<\/li>\n<li>Setup a remote for the try server:<br \/>\n<blockquote>\n<pre>$ git remote add try hg::https:\/\/hg.mozilla.org\/try\r\n$ git config remote.try.skipDefaultUpdate true\r\n$ git remote set-url --push try hg::ssh:\/\/hg.mozilla.org\/try\r\n$ git config remote.try.push +HEAD:refs\/heads\/branches\/default\/tip\r\n<\/pre>\n<\/blockquote>\n<\/li>\n<li>Update all the remotes:<br \/>\n<blockquote>\n<pre>$ git remote update<\/pre>\n<\/blockquote>\n<p>This essentially does <code>git fetch<\/code> on all remotes, except try.\n<\/li>\n<\/ul>\n<p>With this setup, you can e.g. create new topic branches based on the remote branches:<\/p>\n<blockquote>\n<pre>$ git checkout -b bugxxxxxxx inbound\/branches\/default\/tip<\/pre>\n<\/blockquote>\n<p>or<\/p>\n<blockquote>\n<pre>$ git checkout -b bugxxxxxxx inbound\/default<\/pre>\n<\/blockquote>\n<p>depending on your <code>remote.inbound.fetch<\/code> settings (see above).<\/p>\n<p>When you're ready to test your code on try, create a commit with the <a href=\"https:\/\/wiki.mozilla.org\/ReleaseEngineering\/TryServer#How_to_push_to_try\">try syntax<\/a>, then just do:<\/p>\n<blockquote>\n<pre>$ git push try<\/pre>\n<\/blockquote>\n<p>This will push whatever your checked-out branch is, to the try server (thanks to the refspec in <code>remote.try.push<\/code>).<\/p>\n<p>When you're ready to push to an integration branch, remove any try commit. Assuming you were using the topic branch from above, and did set <code>push.default<\/code> to \"upstream\", push with:<\/p>\n<blockquote>\n<pre>$ git checkout topic-branch\r\n$ git pull --rebase\r\n$ git push<\/pre>\n<\/blockquote>\n<p>But, this is only one possibility. You're essentially free to pick your own preferred workflow. Just keep in mind that we generally prefer linear history on integration branches, so prefer rebase to merge (and, git-cinnabar doesn't support pushing merges yet). I'd recommend setting the <code>pull.ff<\/code> configuration to \"only\", by the way.<\/p>\n<p>Please note that rebasing something you pushed to e.g. try may leave dangling mercurial metadata in your git clone. <code>git hgdebug fsck<\/code> will tell you about them, but won't do anything about them, at least currently. Eventually, there will be a <code>git-gc<\/code>-like command.<\/p>\n<p>Please report any issue you encounter in the comments, or, if they are git-cinnabar related, <a href=\"https:\/\/github.com\/glandium\/git-cinnabar\/issues\/new\">on github<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is my recommended setup for Gecko development with git: Install mercurial (only needed for its libraries). You probably already have it installed. Eventually, this dependency will go away, because the use of mercurial libraries is pretty limited. Use git 2.2.2 or newer, or rebuild an older git with this patch applied: https:\/\/github.com\/git\/git\/commit\/61e704e38a4c3e181403a766c5cf28814e4102e4. It will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-3438","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/pages\/3438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3438"}],"version-history":[{"count":5,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/pages\/3438\/revisions"}],"predecessor-version":[{"id":3500,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/pages\/3438\/revisions\/3500"}],"wp:attachment":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}