Getting Checkboxes to work on Frontend Forms
The first loop you're using loops over entry.gistCategories.options, which contains all the options available. However, in the second loop (when entry.gistCategories|length !== 0), you're only looping over the options that have been selected.

Try this:

{% if entry.gistCategories | length == 0 %}
    &lt;ul&gt;
        {% for option in entry.gistCategories.options %}
            {# output checkboxes #}
        {% endfor %}
    &lt;/ul&gt;
{% else %}  
    &lt;ul&gt;
        {% for checkboxOption in entry.gistCategories.options %}
            {# output checkboxes #}
        {% endfor %}
    &lt;/ul&gt;
{% endif %}