109

Is there a way to control the order in which files appear in a gist? They don't seem to be alphabetical or chronological. I'd like to have a README.md appear as the first file in a multi-file gist, but no amount of "deleting" a file and re-adding it seems to change anything.

Is there an order to these files that I'm not seeing, or does GitHub maintain an internal filetype priority list?

Sinetheta
  • 9,189
  • 5
  • 31
  • 52

4 Answers4

125

Since at least 2018, the order is alphabetical, with periods and numbers coming before letters.

That is, as mentioned in Andrew D.Bond's answer:

  1. $
  2. . (dot)
  3. Numbers
  4. Leading space (although the space doesn't appear after saving, the sort order is still updated)
    (although bis, in Sept. 2020, IvanaGyro adds in the comments leading spaces will not affect the order any more)
  5. _ (underscore)
  6. Letters (case insensitive)

Around 2013-2014 a different order was used. See Andrew D. Bond's answer for more.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    Awesome, thanks. I've never really thought of "case" when considering sort order. – Sinetheta Jul 16 '13 at 17:29
  • @Barney strange, it was working for me. That should be answered by Github support then: https://github.com/contact – VonC Sep 10 '13 at 13:52
  • @Barney I just [forked your repo](https://gist.github.com/Sinetheta/6510464) and it seems to be working. Which rule of ASCIIbetical is not being applied? Yes, Uppercase before Lower, but when the same case [L before R](http://www.youtube.com/watch?v=5XEN4vtH4Ic). – Sinetheta Sep 10 '13 at 14:59
  • @Sinetheta you're absolutely right — I don't know how I managed to screw that up but when I try now it's fine. I retract all the above and I've updated the Gist team at GitHub. – Barney Sep 11 '13 at 08:40
  • 33
    i wish i could order my own files – Connor Leech Aug 10 '14 at 06:17
  • 3
    @ConnorLeech well, you can, after a fashion: http://stackoverflow.com/a/20949455/6309 – VonC Aug 10 '14 at 06:38
  • This answer is wrong and/or out-of-date: [`URL.cgi` is listed after both `hiawatha-url.conf.include` and `example.url`](https://gist.github.com/b845f0f9f06cb0db42918107e9eda18c/463d3054a533e7d042aab469475a045aeac71c8c). So if ASCIIbetical really implies caps trump lowercase, it's definitely NOT being used. – JamesTheAwesomeDude Jun 21 '18 at 19:35
  • @JamesTheAwesomeDude I agree. I have edited my 5-years old answer: the order seems more alphabetical now. – VonC Jun 21 '18 at 19:43
  • It seems that adding leading spaces will not affect the order any more (2020.09.15). – IvanaGyro Sep 15 '20 at 05:34
  • @IvanaGyro Thank you for this feedback. I have included your comment in the answer for more visibility. – VonC Sep 15 '20 at 05:36
  • Note to self: 300th Great Answer gold badge, a bit [more than 31 months](https://www.timeanddate.com/date/durationresult.html?d1=15&m1=05&y1=2018&d2=27&m2=12&y2=2020) after the [200th Great Answer gold badge](https://stackoverflow.com/a/2250170/6309). – VonC Dec 27 '20 at 21:36
  • It's 2021 and I still can't manually reorder my own files! – Andrew Schultz Aug 05 '21 at 10:11
15

They are ordered automatically by name, following the ASCII table.

Unfortunatly, right now, it is not possible to order them by dragging, but there is a trick. You can control the order by adding one or more spaces before the name. The space will not be shown after editing, but the order will change.

E.g: lets say we have 3 files with the automatic order:

  • AFile.java
  • Readme.md
  • SomeFile.txt

We can invert the order by putting spaces like this:

  • (space)(space)SomeFile.txt
  • (space)Readme.md
  • AFile.txt
Mario Velasco
  • 3,336
  • 3
  • 33
  • 50
  • I can't get this to work. I've added spaces to the beginning of the title name, and it doesn't seem to affect the order. I'm trying to mark "part 1 and part 2" as the first file(notebook) of the list of files within this repository. https://github.com/moondra2017/Python-Regular-Expressions – Moondra Sep 18 '17 at 00:07
  • 1
    @Moondra The question is talking about ordering gists. That are normal github files – Mario Velasco Sep 18 '17 at 08:31
  • @MarioVelasco I see. Thanks for the clarification. – Moondra Sep 18 '17 at 15:25
  • 10
    This workaround (if it ever worked) is broken. Adding spaces to the front of a filename is ineffectual. – JamesTheAwesomeDude Jun 21 '18 at 19:49
  • 1
    I ended up using dashes control this. And since the filename `README.md` doesn't have any major effect (except the `.md` extension), I just name the file the title that I'd like to use for the gist, e.g. `- How to Foo Bar.md`. That way not only does it show up first, but the main title is more descriptive. For example: https://gist.github.com/patricknelson/57ae24986cb13613314fb1f3c00a95d7 – patricknelson Sep 06 '19 at 20:52
  • Spaces still seem to work if pushing edits from a git clone of the gist, but it seems that editing the gist from the GitHub GUI will strip out leading spaces. So still kinda works, but fragile (only if you're willing to edit from a local clone, and perhaps subject to future changes/prohibitions on GitHub's part). – Max Starkenburg Feb 13 '21 at 20:12
12

Updating my answer from an earlier year with additional testing I did just now:

Github automatically sorts files in a gist according to:

  1. #
  2. $
  3. . (period)
  4. Numbers
  5. _ (underscore)
  6. Letters (case insensitive)

Leading spaces are dropped.

If additional characters' sort order is discovered, feel free to edit this answer.

(Added this answer because even after I improved another answer to this question last year, I still couldn't find the sort order of special characters anywhere.)

Andrew D. Bond
  • 902
  • 1
  • 11
  • 11
10

As mentioned by @VonC in his answer, the order is asciibetical. Quick solution would be to prefix all files with numbers indicating the order in which you wish the files to appear, example 0_, 1_, 2_, ... 9_. Note, this solution will not work beyond 9 files as 10_ will appear before 2_. In that case, two digits need to be used 00_, 01_, 02_, ..., 09_, 10_, 11_, ... This can be generalized to any number of digits in the number of files. Although, it seems less likely, to me, that more more than 10 files to be shared in a gist.

Sourabh Daptardar
  • 259
  • 1
  • 3
  • 7