<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[AlBlue&rsquo;s Blog]]></title>
  <link href="https://alblue.bandlem.com/Tag/gtotw/atom.xml" rel="self"/>
  <link href="https://alblue.bandlem.com/"/>
  <updated>2021-03-10T23:28:02+00:00</updated>
  <id>https://alblue.bandlem.com/</id>
  <author>
    <name><![CDATA[Alex Blewitt]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Git Tip of the Week: Finale]]></title>
    <link href="https://alblue.bandlem.com/2011/12/git-tip-of-week-finale.html"/>
    <updated>2011-12-20T09:00:00+00:00</updated>
    <id>https://alblue.bandlem.com/2011/12/git-tip-of-week-finale</id>
    <content type="html"><![CDATA[<p>Over the past nine months, I’ve been writing a series called the <a href="/Tag/gtotw/">Git Tip of the Week</a> series, where I write about a
Git-related article every week. Part of this has been a desire to learn more
about the way the Git internals works; part is to provide a reference for
others to find out about as well.</p>

<p>However, all good things must come to an end, and writing a weekly post, whilst
keeping it fresh, is a non-trivial task. In addition, finding something new (or
even vaguely interesting) to write about is increasingly difficult once you’ve
covered the standard cases and a number of esoteric ones.</p>

<p>So, for my final post in the series, rather than writing about something new, I
thought I’d link back to the ones that I’ve written before, in order. Thus, if
you want to share the series with others, you can refer back to this index page
as a means of finding out what I wrote when. The <a href="/Tag/gtotw/">search list</a> is all well and good, but it only shows the top 20 most recent posts.
In addition, I’ve added some of my other Git related articles that may be of
interest, even though they weren’t part of the Git Tip of the Week series.</p>

<!-- more -->

<h2 id="prior-posts">Prior Posts</h2>

<ul>
  <li><a href="/2010/02/git-for-eclipse-users.html">Introduction to DVCS</a></li>
  <li><a href="/2011/02/someday.html">Using Gerrit for source review</a></li>
  <li><a href="/2011/02/gerrit-git-review-with-jenkins-ci.html">Video demo of using Git, Gerrit and Jenkins in action</a></li>
  <li><a href="/2011/05/git-gerrit-and-jenkins-for-ios.html">Video demo of using Git, Gerrit and Jenkins for iOS development</a></li>
  <li><a href="/2011/06/running-gerrit-with-jenkinshudson.html">Tutorial on how to set up Gerrit and Jenkins</a></li>
</ul>

<h2 id="march-2011">March 2011</h2>
<ul>
  <li><a href="/2011/03/git-tip-of-week-setting-up-shared.html">Setting up a shared repository</a></li>
  <li><a href="/2011/03/git-tip-of-week-adding-content.html">Adding content</a></li>
  <li><a href="/2011/03/git-tip-of-week-ignoring-build-output.html">Ignoring build output</a></li>
  <li><a href="/2011/03/git-tip-of-week-pushing-and-pulling.html">Pushing and Pulling</a></li>
</ul>

<h2 id="april-2011">April 2011</h2>
<ul>
  <li><a href="/2011/04/git-tip-of-week-aliases.html">Aliases</a></li>
  <li><a href="/2011/04/git-tip-of-week-branches.html">Branches</a></li>
  <li><a href="/2011/04/git-tip-of-week-merging.html">Merging</a></li>
  <li><a href="/2011/04/git-tip-of-week-tags.html">Tags</a></li>
</ul>

<h2 id="may-2011">May 2011</h2>
<ul>
  <li><a href="/2011/05/git-tip-of-week-gollum.html">Gollum</a></li>
  <li><a href="/2011/05/git-tip-of-week-stashes.html">Stashes</a></li>
  <li><a href="/2011/05/git-tip-of-week-reflogs.html">Reflogs</a></li>
  <li><a href="/2011/05/git-tip-of-week-git-revisions.html">Git Revisions</a></li>
</ul>

<h2 id="june-2011">June 2011</h2>
<ul>
  <li><a href="/2011/06/git-tip-of-week-rebasing.html">Rebasing</a></li>
  <li><a href="/2011/06/git-tip-of-week-cherry-picking.html">Cherry Picking</a></li>
  <li><a href="/2011/06/git-tip-of-week-rebasing-revisited.html">Rebasing Revisited</a></li>
  <li><a href="/2011/06/git-tip-of-week-egit.html">EGit</a></li>
  <li><a href="/2011/06/git-tip-of-week-pulling-and-rebasing.html">Pulling and Rebasing</a></li>
</ul>

<h2 id="july-2011">July 2011</h2>
<ul>
  <li><a href="/2011/07/git-tip-of-week-tracking-branches.html">Tracking Branches</a></li>
  <li><a href="/2011/07/git-tip-of-week-assigning-blame.html">Assigning Blame</a></li>
  <li><a href="/2011/07/git-tip-of-week-autocompletion-in.html">Autocompletion in Shells</a></li>
  <li><a href="/2011/07/git-tip-of-week-git-bisect.html">Git Bisect</a></li>
</ul>

<h2 id="august-2011">August 2011</h2>
<ul>
  <li><a href="/2011/08/git-tip-of-week-searching-for-patterns.html">Searching for Patterns</a></li>
  <li><a href="/2011/08/git-tip-of-week-searching-for-commits.html">Searching for Commits and Changes</a></li>
  <li><a href="/2011/08/git-tip-of-week-detached-heads.html">Detached Heads</a></li>
  <li><a href="/2011/08/git-tip-of-week-objects.html">Objects</a></li>
  <li><a href="/2011/08/git-tip-of-week-trees.html">Trees</a></li>
</ul>

<h2 id="september-2011">September 2011</h2>
<ul>
  <li><a href="/2011/09/git-tip-of-week-commits.html">Commits</a></li>
  <li><a href="/2011/09/git-tip-of-week-objects-and-packfiles.html">Objects and Packfiles</a></li>
  <li><a href="/2011/09/git-tip-of-week-packfiles-redux.html">Packfiles redux</a></li>
  <li><a href="/2011/09/git-tip-of-week-git-archive.html">Git Archive</a></li>
</ul>

<h2 id="october-2011">October 2011</h2>
<ul>
  <li><a href="/2011/10/git-tip-of-week-interactive-adding.html">Interactive Adding</a></li>
  <li><a href="/2011/10/git-tip-of-week-understanding-index.html">Understanding the Index</a></li>
  <li><a href="/2011/10/git-tip-of-week-index-revisited.html">Index Revisited</a></li>
  <li><a href="/2011/10/git-tip-of-week-merging-revisited.html">Merging Revisited</a></li>
</ul>

<h2 id="november-2011">November 2011</h2>
<ul>
  <li><a href="/2011/11/git-tip-of-week-git-flow.html">Git Flow</a></li>
  <li><a href="/2011/11/git-tip-of-week-git-notes.html">Git Notes</a></li>
  <li><a href="/2011/11/git-tip-of-week-gc-and-pruning-this.html">GC and Pruning</a></li>
  <li><a href="/2011/11/git-tip-of-week-git-bigjobbies.html">Git BigJobbies</a></li>
  <li><a href="/2011/11/git-tip-of-week-git-submodules.html">Submodules</a></li>
</ul>

<h2 id="december-2011">December 2011</h2>
<ul>
  <li><a href="/2011/12/git-tip-of-week-patches-by-email.html">Patches</a></li>
  <li><a href="/2011/12/git-tip-of-week-forking-and-pulling-vs.html">Forking vs Pulling</a></li>
  <li><a href="/2011/12/git-tip-of-week-finale.html">Finale</a></li>
</ul>

<p>I’d like to thank you for your time and interest in reading this series, and
wish you a happy Christmas and a prosperous New Year.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Git Tip of the Week: Forking and Pulling vs Pushing]]></title>
    <link href="https://alblue.bandlem.com/2011/12/git-tip-of-week-forking-and-pulling-vs.html"/>
    <updated>2011-12-13T09:00:00+00:00</updated>
    <id>https://alblue.bandlem.com/2011/12/git-tip-of-week-forking-and-pulling-vs</id>
    <content type="html"><![CDATA[<p>This week’s <a href="/Tag/gtotw/">Git Tip of the Week</a> is about the GitHub
generation. You can subscribe to the <a href="/Tag/gtotw/atom.xml">feed</a> if
you want to receive new instalments automatically.</p>

<!-- more -->
<hr />

<p>Distributed Version Control Systems have really taken off in the last few
years, though they’ve been around for over a decade. Probably the biggest
growth spurt happened because of the
<a href="http://www.pcworld.idg.com.au/article/129776/after_controversy_torvalds_begins_work_git_/">controversy that launched Git</a> back in April 2005, providing a rock solid distributed
version control system, modelled on a filesystem. In only a few months, Git
began
<a href="http://marc.info/?l=git-commits-head&amp;m=111904216911731">hosting the 2.6.12 Linux kernel source</a>.</p>

<p>However, as popular as Git may have been then, it wasn’t until the birth of
<a href="http://github.com">GitHub</a> until Git really took off. Founded in
February 2008, GitHub brought Git to a much wider audience and provided a free
hosting site for public Git repositories (as well as commercial plans for
private repositories.) It has been argued that GitHub is one of the reasons why
Git has taken off faster than others, like Hg and Bzr.</p>

<p>What GitHub brought was a focus on a new model; instead of creating patches (as
<a href="/2011/12/git-tip-of-week-patches-by-email.html">covered last time</a>),
GitHub encouraged universal <em>forking</em> of the repository. So,
if you want to add a change to an existing repository, you can fork it (and
create your own clone), make the changes, and then send a <em>pull
request</em>.</p>

<p>There’s nothing significant about pull requests in the Git workflow as compared
with other DVCS tools. Pushing and pulling are two key primitives in a DVCS
workflow, after all. But what was novel about GitHub’s approach was the way
that pull requests could be sent, as an out-of-band message to the upstream
repository owner suggesting the idea.</p>

<p>Not only that, but the upstream owner would then get a notification and be able
to view the request in situ, and with the diffs as appropriate (outside of a
mail client, via the web interface). Subsequent advances, such as the ability
to fork-to-fix-typos, meant that anyone could suggest changes via the web
without even needing to compile the code locally.</p>

<h2 id="pushing-pulling-patching-or-proposing">Pushing, Pulling, Patching or Proposing</h2>

<p>As a result, Git repositories can end up with different workflows depending on
the type of project and hosting environment you are using. They are:</p>

<ul>
  <li><strong>Pushing</strong>: You have access to directly write into the repository, so you just push your changes</li>
  <li><strong>Pulling</strong>: Someone has changes locally and asks you to pull the change from their repository</li>
  <li><strong>Patching</strong>: You send the diffs/patches by a transport mechanism (bugzilla, email) for consideration</li>
  <li><strong>Proposing</strong>: You use a tool like Gerrit to propose changes to which can then subsequently be merged</li>
</ul>

<p>Each project has potentially a different style of operation, and there isn’t a
“right” way to use a Git repository. GitHub, for example, strongly favours the
Pulling model when consuming changes from others (though of course, the
repository owner can do pushing directly). The Linux Kernel, both for historic
reasons and also for transparency and open discussions, chooses the patching
(by e-mail) model.</p>

<p>The final one – proposing – is a combination of both the pull, push
and patch models. They’re similar to GitHub’s pull mechanism, in that the
project’s owners can see a list of all incoming changes and decide which ones
to use; but the push-based upload means that the original repository doesn’t
have to be forked on the remote server. And finally, tools like Gerrit (which
I’ve <a href="/Tag/gerrit/">mentioned before</a>) can be used to generate
patches, host in-situ discussions, and even act as a Git repository for
consuming by standard <code class="language-plaintext highlighter-rouge">git fetch</code> protocols.</p>

<p>GitHub’s pull-based approach has certainly had a wide impact on the number of
users willing to try that method. They have a <a href="http://help.github.com/send-pull-requests/">note on collaborative development models</a> on the subject:</p>

<blockquote>
  <ol>
    <li>
      <p>The <em>Fork + Pull</em> Model lets anyone fork an existing repository and push
changes to their personal fork. This model reduces the amount of friction for
new contributors and is popular with open source projects because it allows
people to work independently without upfront coordination.</p>
    </li>
    <li>
      <p>The <em>Shared Repository</em> Model is more prevalent with small teams and
organizations collaborating on private projects. Everyone is granted push
access to a single shared repository and topic branches are used to isolate
changes.</p>
    </li>
  </ol>
</blockquote>

<p>Certainly, if there are minor changes (like a typo in documentation) the
fork-and-pull model, when combined with a web-based interface, can make things
dramatically easier for contributors. Instead of having to need to create
accounts on bug tracking systems (or tools like Gerrit), the repository can be
forked, fixed, and a pull request fired off to the repository maintainers. With
the <a href="https://github.com/blog/843-the-merge-button">merge button</a> in
GitHub, it can often be the case of allowing the fix to be merged in without
the maintainer having to check the code out at all, if it’s sufficiently
simple. Reducing the barrier to accepting changes helps keep an active
open-source project alive and open to all.</p>

<p>The only problem with the Fork + Pull model is being able to attribute changes
by user. For example, some open-source foundations want to ensure that any
changes are granted against an existing open source license (Apache or Eclipse,
for example). Other projects tend not to be as strict and will happily accept
contributions from anyone, with the assumption that any contributors have
agreed to the license. One additional service that patches-to-bugzilla or
gerrit push provide is in the acceptance of a contributor agreement, which
normally states that the individual is entitled to grant the code under the
specific licence. One of the side-effects of creating an account often implies
(explicitly or implicitly) the agreement to follow that foundation’s licensing
rules.</p>

<p>So, there’s no “right” way to do Git; different teams, foundations and projects
will have their own preference for working with a particular strategy, and may
evolve over time. Instead, it’s useful to know what’s available so that the
right choice for that project can be made, understanding the different flows
available.</p>

<hr />

<p>Come back next week for another instalment in the Git Tip of the Week series.</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Git Tip of the Week: Patches by Email]]></title>
    <link href="https://alblue.bandlem.com/2011/12/git-tip-of-week-patches-by-email.html"/>
    <updated>2011-12-06T09:00:00+00:00</updated>
    <id>https://alblue.bandlem.com/2011/12/git-tip-of-week-patches-by-email</id>
    <content type="html"><![CDATA[<p>This week's <a href="/Tag/gtotw/">Git Tip of the Week</a> is about how git handles patches by email. You can subscribe to the <a href="/Tag/gtotw/">feed</a> if you want to receive new instalments automatically.</p>
<!-- more -->
<hr/>
<p>
One of the main benefits of a distributed version control system is that code changes can be pushed from one repository to another clone, and all dependent changes are pushed as well. However, that only works when you have write access to the remote repository, which in many cases you do not. One way of getting changes is by providing a <em>patch</em>, or a set of changes which can be applied to a remote repository at the other end.
</p>
<p>
Git started life as a distributed version control system for the Linux project, which actively uses mail lists both as a discussion mechanism and also as a distribution mechanism for patches (changes) for an existing codebase. (New features are just a special case of patching nothing to add the new code.)
</p>
<p>
To speed the processing of patches by mail, git developed tight integration with both (command-line) mail clients and of the generic Unix <code>mbox</code> format. Patches can be generated in the form of mail messages, and the remote end can process them with a specific command to reconstitute the changes in the git repository.
</p>
<p>
Whilst the majority of projects don't use patches by mail as a change distribution mechanism, it is useful on occasion where either a patch needs to be generated and attached to a bug tracking system, or where changes need to be sent to a remote developer who doesn't have direct access (such as through a firewall).
</p>
<p>
The convention adopted by the git developers is to format one patch per e-mail message. The subject of the message then has the first line of the git commit, prefixed with a prefix that can be overridden on the command line but which defaults to <code>[PATCH x/y]</code> as a means of threading them together. (Amongst other reasons, this is why the initial line of a Git commit message is suggested to be relatively short, so that it fits with a mail client's view of the subject and suggested prefix.)
</p>
<p><b>Generating and sending patches</b></p>
<p>How do we generate these patches? The <code>git format-patch</code> will generate a patch-file-per-commit in the range required, formatted ready to go as mail messages in <code>mbox</code> format. The <code>--to</code> can be specified for which mail address the patches should be sent to &ndash; but the sending is done separately.
</p>
<blockquote><pre><code>
(master) $ git format-patch --to cdt-dev@eclipse.org HEAD~..HEAD
0001-bug-333001-Description-Scanner-Info-doesn-t-release.patch
From 9c9c692df50e5a9eb91b41cc86f57212afd78ef9 Mon Sep 17 00:00:00 2001
From: Andrew Gvozdev &hellip;
Date: Sat, 16 Jul 2011 15:16:21 -0400
Subject: [PATCH] bug 333001: Description Scanner Info doesn't release
 ICProjectDescription
To: cdt-dev@eclipse.org

---
 .../cdt/internal/core/model/CModelManager.java     |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
&vellip;
</code></pre></blockquote>
<p>
If the commit message has more detail than a single line, the detail will be included below the mail's subject headers. It's possible to add additional commentary below the commit message, before the patch is shown, and any text up until a combination of --- or <code>&gt;8</code> or  <code>8&lt;</code> (<abbr title="Also known as">AKA </abbr> 'scissor lines') is ignored by the patch application at the other end.
</p>
<p>
These patch files can then be transmitted via mail using the <code>git send-email</code> command. This connects to the given SMTP server (either the one from your global <code>~/.gitconfig</code> or the project's <code>.gitconfig</code>, or the one specified on the command line) and then sends each patch file as a separate e-mail:
</p>
<blockquote><pre><code>
(master) $ git send-email --smtp-server=smtp.gmail.com *.patch
</code></pre></blockquote>
<p>
As well as using <code>format-patch</code> in a separate stage, it's possible to use <code>send-email</code> to generate the patches and then send them immediately. (You can also configure <code>send-mail</code> to prompt to open an editor so that you can customise the messages before they are sent.)
</p>
<p><b>Applying patches</b></p>
<p>Once the patches have been created, how do you apply them into a local clone? If you have a patch file, you can apply it with <code>git apply</code>:</p>
<blockquote><pre><code>
(master) $ git apply 0001-bug-333001-Description-Scanner-Info-doesn-t-release.patch
</code></pre></blockquote>
<p>
Note, however, that this approach does not recreate the state of the world as it was on the sender's repository. Instead, the patch is applied but it only makes local changes to the repository's content instead; it does not recreate the commit (and more specifically, the hash of that commit). You can specify <code>git apply --index</code> and <code>git apply --cached</code> to get the changes put into the staging area, but this does not recreate the same commit as before.
</p>
<p>
To recreate the commit as it was exactly requires the use of <code>git am</code>, which stands for <em>apply mailbox</em>. This runs through a mailbox (which may have one or more patches in it) and recreates a commit for each one of those patches.
</p>
<p>
Fortunately, the output generated by <code>git patch</code> is already in <code>mbox</code> format; it's the purpose of the otherwise dummy <code>From 9c9c692df50e5a9eb91b41cc86f57212afd78ef9 Mon Sep 17 00:00:00 2001</code> line at the top of the patch file. As a result, the patches can be treated as one message per <code>mbox</code>, and then applied in batch to the changes which get sent.
</p>
<p>
In fact, since <code>mbox</code> elements can be concatenated together, this permits patch files to be concatenated together to form a larger patch file, which can be sent as a single unit via another transfer mechanism and then applied on the remote side.
</p>
<p><b>Bundles</b></p>
<p>
Patches provide a way of reconstituting a repository over a not directly connected mechanism, but the purpose of patches are to enable humans to investigate the set of changes as much as getting the change there. If however the desire is to move commits from one machine to another without direct connectivity, a better alternative is to use <code>git bundle</code>.
</p>
<blockquote><pre><code>
(master) $ git bundle create changes.bundle HEAD~..HEAD
Counting objects: 23, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (12/12), 935 bytes, done.
Total 12 (delta 5), reused 6 (delta 0)
</code></pre></blockquote>
<p>
The format of the <code>bundle</code> uses the same format as the network transmission that Git uses over the network when cloning. As a result, the references contained are only those listed in the reference list.
</p>
<p>
Typically, a tag will be used to mark where the last known point was for the remote source; then, the difference between HEAD and that tag is used to build up the bundle for the remote end. Alternatively, branches can be used to simulate the branch on the remote end.
</p>
<p>
Once the bundle file has been generated, it can be sent over any transport to the remote host for reconstitution. This might involve burning to a CD, via a USB stick or some other network protocol.
</p>
<p>
On the client side, the client can run <code>git verify</code> to determine if all required parent commits are present in the local repository. This must be run from the client git repository that you want to fetch into.
</p>
<p>
The client views the bundle as a remote that it can pull from, much like a path to a directory can be used to pull from a local file-based repository. You can add it as a remote (e.g. <code>git remote add changes /tmp/changes.bundle</code>) or you can fetch from the path to the bundle itself:
</p>
<blockquote><pre><code>
(master) $ git verify /tmp/changes.bundle
The bundle contains 1 ref
b707c559636bf8e6dffb3145bd44b03de18868b3 HEAD
The bundle requires these 1 ref
3580c1087c2860fbe6ca4c1a7a6d6e1eb1669aa3 Bug 333599 - [C++0x] Initializer lists & return without type
/tmp/changes.bundle is okay
(master) git fetch /tmp/changes.bundle
From /tmp/foo.bundle
 * branch            HEAD       -> FETCH_HEAD
</code></pre></blockquote>
<p>
Once the references have been fetched into the repository (which can be referred to as <code>FETCH_HEAD</code>) you can then inspect the changes, fetch/merge them into the local branches or reset your <code>master</code> branch to that of <code>FETCH_HEAD</code>.
</p>
<p><b>Summary</b></p>
<p>
It's not always possible to have write access to the repository you want to send changes to. In those cases you can send changes out of band, either via mail (if you want human reviews) or as a bundle (if you just want to send the commits).
</p>

<hr/>
<p>Come back next week for another instalment in the Git Tip of the Week series.</p>
]]></content>
  </entry>
  
</feed>
