Another way to make a directory stay (almost) empty (in the repository) is to create a .gitignore
file inside that directory that contains these four lines:
# Ignore everything in this directory
*
# Except this file
!.gitignore
Then you don't have to get the order right the way that you have to do in m104's solution.
This also gives the benefit that files in that directory won't show up as "untracked" when you do a git status.
Making @GreenAsJade's comment persistent:
I think it's worth noting that this solution does precisely what the question asked for, but is not perhaps what many people looking at this question will have been looking for. This solution guarantees that the directory remains empty. It says "I truly never want files checked in here". As opposed to "I don't have any files to check in here, yet, but I need the directory here, files may be coming later".
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…