Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Uncategorized
  3. Git won't track empty directories (because at heart it only tracks files).

Git won't track empty directories (because at heart it only tracks files).

Scheduled Pinned Locked Moved Uncategorized
12 Posts 10 Posters 0 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • nedbat@hachyderm.ioN This user is from outside of this forum
    nedbat@hachyderm.ioN This user is from outside of this forum
    nedbat@hachyderm.io
    wrote last edited by
    #1

    Git won't track empty directories (because at heart it only tracks files). Common advice is to add a '.gitkeep' file so the directory isn't empty and git will make the directory.

    EVEN BETTER ADVICE: put a README in the directory explaining what the empty directory is for and what will eventually be there.

    mgorny@social.treehouse.systemsM lattera@bsd.networkL doekman@mastodon.nlD airtower@woem.menA jg@social.jg.devJ 8 Replies Last reply
    2
    0
    • nedbat@hachyderm.ioN nedbat@hachyderm.io

      Git won't track empty directories (because at heart it only tracks files). Common advice is to add a '.gitkeep' file so the directory isn't empty and git will make the directory.

      EVEN BETTER ADVICE: put a README in the directory explaining what the empty directory is for and what will eventually be there.

      mgorny@social.treehouse.systemsM This user is from outside of this forum
      mgorny@social.treehouse.systemsM This user is from outside of this forum
      mgorny@social.treehouse.systems
      wrote last edited by
      #2

      @nedbat, but if you put README in there it's no longer empty, and if it must be empty, then that is not going to work :-).

      1 Reply Last reply
      0
      • nedbat@hachyderm.ioN nedbat@hachyderm.io

        Git won't track empty directories (because at heart it only tracks files). Common advice is to add a '.gitkeep' file so the directory isn't empty and git will make the directory.

        EVEN BETTER ADVICE: put a README in the directory explaining what the empty directory is for and what will eventually be there.

        lattera@bsd.networkL This user is from outside of this forum
        lattera@bsd.networkL This user is from outside of this forum
        lattera@bsd.network
        wrote last edited by
        #3

        @nedbat I usually have a .gitignore file with the following data:

        *
        !.gitignore
        jasonkarns@indieweb.socialJ 1 Reply Last reply
        0
        • nedbat@hachyderm.ioN nedbat@hachyderm.io

          Git won't track empty directories (because at heart it only tracks files). Common advice is to add a '.gitkeep' file so the directory isn't empty and git will make the directory.

          EVEN BETTER ADVICE: put a README in the directory explaining what the empty directory is for and what will eventually be there.

          doekman@mastodon.nlD This user is from outside of this forum
          doekman@mastodon.nlD This user is from outside of this forum
          doekman@mastodon.nl
          wrote last edited by
          #4

          @nedbat But what do you do when all files from a folder are deleted in a certain commit. Leave a readme that this folder was once there for some kind of reason? Otherwise all people who once had pulled that commit end up with an empty folder that's not used for any thing...

          kiloku@burnthis.townK 1 Reply Last reply
          0
          • nedbat@hachyderm.ioN nedbat@hachyderm.io

            Git won't track empty directories (because at heart it only tracks files). Common advice is to add a '.gitkeep' file so the directory isn't empty and git will make the directory.

            EVEN BETTER ADVICE: put a README in the directory explaining what the empty directory is for and what will eventually be there.

            airtower@woem.menA This user is from outside of this forum
            airtower@woem.menA This user is from outside of this forum
            airtower@woem.men
            wrote last edited by
            #5

            @nedbat@hachyderm.io Another option that'd often (but maybe not always) be preferable: create the directory when it's needed, e.g. during build.

            jasonkarns@indieweb.socialJ 1 Reply Last reply
            0
            • pixelate@tweesecake.socialP pixelate@tweesecake.social shared this topic
            • nedbat@hachyderm.ioN nedbat@hachyderm.io

              Git won't track empty directories (because at heart it only tracks files). Common advice is to add a '.gitkeep' file so the directory isn't empty and git will make the directory.

              EVEN BETTER ADVICE: put a README in the directory explaining what the empty directory is for and what will eventually be there.

              jg@social.jg.devJ This user is from outside of this forum
              jg@social.jg.devJ This user is from outside of this forum
              jg@social.jg.dev
              wrote last edited by
              #6

              @nedbat Solid advice!

              1 Reply Last reply
              0
              • lattera@bsd.networkL lattera@bsd.network

                @nedbat I usually have a .gitignore file with the following data:

                *
                !.gitignore
                jasonkarns@indieweb.socialJ This user is from outside of this forum
                jasonkarns@indieweb.socialJ This user is from outside of this forum
                jasonkarns@indieweb.social
                wrote last edited by
                #7

                @lattera @nedbat I must admit to liking the readme idea more.

                But I do wish subdir .gitignore was the default convention for templates and scaffolding than .keep files.

                1 Reply Last reply
                0
                • airtower@woem.menA airtower@woem.men

                  @nedbat@hachyderm.io Another option that'd often (but maybe not always) be preferable: create the directory when it's needed, e.g. during build.

                  jasonkarns@indieweb.socialJ This user is from outside of this forum
                  jasonkarns@indieweb.socialJ This user is from outside of this forum
                  jasonkarns@indieweb.social
                  wrote last edited by
                  #8

                  @airtower love this.

                  Versioning the empty dirs is a bandaid that addresses the symptom, not the root cause!!

                  1 Reply Last reply
                  0
                  • nedbat@hachyderm.ioN nedbat@hachyderm.io

                    Git won't track empty directories (because at heart it only tracks files). Common advice is to add a '.gitkeep' file so the directory isn't empty and git will make the directory.

                    EVEN BETTER ADVICE: put a README in the directory explaining what the empty directory is for and what will eventually be there.

                    thatdnaguy@genomic.socialT This user is from outside of this forum
                    thatdnaguy@genomic.socialT This user is from outside of this forum
                    thatdnaguy@genomic.social
                    wrote last edited by
                    #9

                    @nedbat I think I like this better. It at least gives you the ability to explain purpose instead of just hacking git to follow it.

                    1 Reply Last reply
                    0
                    • nedbat@hachyderm.ioN nedbat@hachyderm.io

                      Git won't track empty directories (because at heart it only tracks files). Common advice is to add a '.gitkeep' file so the directory isn't empty and git will make the directory.

                      EVEN BETTER ADVICE: put a README in the directory explaining what the empty directory is for and what will eventually be there.

                      notmyname@mastodon.socialN This user is from outside of this forum
                      notmyname@mastodon.socialN This user is from outside of this forum
                      notmyname@mastodon.social
                      wrote last edited by
                      #10

                      @nedbat @chrisjrn “This path is intentionally blank”

                      1 Reply Last reply
                      0
                      • nedbat@hachyderm.ioN nedbat@hachyderm.io

                        Git won't track empty directories (because at heart it only tracks files). Common advice is to add a '.gitkeep' file so the directory isn't empty and git will make the directory.

                        EVEN BETTER ADVICE: put a README in the directory explaining what the empty directory is for and what will eventually be there.

                        kiloku@burnthis.townK This user is from outside of this forum
                        kiloku@burnthis.townK This user is from outside of this forum
                        kiloku@burnthis.town
                        wrote last edited by
                        #11

                        @nedbat this feels so obvious and I never thought of it, so thanks for the tip. To be fair to myself, I only resorted to using a .gitkeep once ever

                        1 Reply Last reply
                        0
                        • doekman@mastodon.nlD doekman@mastodon.nl

                          @nedbat But what do you do when all files from a folder are deleted in a certain commit. Leave a readme that this folder was once there for some kind of reason? Otherwise all people who once had pulled that commit end up with an empty folder that's not used for any thing...

                          kiloku@burnthis.townK This user is from outside of this forum
                          kiloku@burnthis.townK This user is from outside of this forum
                          kiloku@burnthis.town
                          wrote last edited by
                          #12

                          @doekman @nedbat if you don't expect the folder to be used anymore, delete the folder as well. In other words, if you can't write a justification for that folders existence in the readme, it doesn't need to exist

                          1 Reply Last reply
                          0
                          • R relay@relay.publicsquare.global shared this topic
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups