-1

I have folder1 and folder 2 under git root folder

gitroot/  
  folder1  
    content...  
  folder2  
    content...  

I want to add folder1 and folder2 to git but don't want to add their content.

I have tried

!folder1
folder1/**
!folder2
folder2/**

which doesn't seem to work. Please advise.

omer
  • 522
  • 1
  • 8
  • 26
  • 2
    git doesn't see folders at all. It only tracks content. Why do you *think* you need to track folders? – Romain Valeri Sep 01 '21 at 14:36
  • 1
    for providing a directory structure in repo. I think, then I need to provide a dummy file. anyways, thanks for the hint. – omer Sep 01 '21 at 14:38
  • 1
    https://stackoverflow.com/search?q=%5Bgit%5D+add+empty+directory – phd Sep 01 '21 at 14:42

1 Answers1

0

Git does not track directories, so you have to rely on a common used trick:

  1. Exclude the folder by .gitignore.
  2. Add an empty file .gitkeep into the folder.
  3. Force adding the above file by git add -f.
Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
  • 2
    if you need to ignore all of the directory's content, you may as well version a single `echo "*" > dir/.gitignore` file in the directory, – LeGEC Sep 01 '21 at 14:46
  • The user asked to track the directory, but not the content, so the solution is the one I provided. – Antonio Petricca Sep 01 '21 at 14:47
  • @AntonioPetricca that works fine too. and your answer as well. Found the solution https://stackoverflow.com/questions/115983/how-can-i-add-a-blank-directory-to-a-git-repository – omer Sep 01 '21 at 14:52
  • https://stackoverflow.com/a/8418403/4669744 here is why I am not going with your solution for now. As other solution fits best to my case. Thnx anyways. – omer Sep 01 '21 at 14:54
  • The two solutions are identical. ;) – Antonio Petricca Sep 01 '21 at 15:00