I have a git repository. It contains many directories and files.

I want the repository to include only:

  • certain directories (bin, Documents);
  • all files that are in the root directory.

My .gitignore now looks like:

 /* !/bin !/Documents /Documents/ViberDownloads /Documents/.~lock* !/.gitignore !/.bash_aliases !/.bash_history !/.bashrc !/.gitconfig !/.profile 

First, I exclude everything /* .

Then I add the bin and Documents directories to the white list.

I ViberDownloads certain data from these subdirectories ( ViberDownloads subdirectory and LibreOffice temporary files).

Now I manually add files from the root directory one by one.

But I have a lot of such files. Is there really no easier way to add all the root files?

  • @alexander barakin, thanks, I forgot the point when copy-paste with English. version. I do not quite understand your question. I want to add two directories - they are added. I want all the files in the root to be added too - they are added, but only if I manually write! / Filename_in_root. And I do not want to write for each file such a line in .gitignore. I want to find a short version, when I use one template, all the files of the root will be immediately added. Do you understand now? - Yura Shinkarev
  • one
    Let's take another. If I’m typing git status on the command line, I’ll get Your branch is up-to-date with 'origin/master' . If I add a new directory to the root and type git status again, I’ll get the same. That is, all folders except bin and Documents will be untraceable. But I want all the files in the root to be tracked. Now this is done only for the following files: .gitignore .bash_aliases .bash_history .bashrc .gitconfig .profile . I see so far only one solution: for the remaining files, manually add the line to .gitignore. But this is a very bad decision - Yura Shinkarev
  • Another attempt :-) I want to track only 2 specific directories and all files in the root directory. But we must understand that in the root directory files can be constantly added / deleted / changed. And to edit each time .gitignore not very desirable in this case. - Yura Shinkarev
  • Let's continue the discussion in the chat . - Yura Shinkarev
  • I have already said all that was necessary to say in the comments: the essence of your question is unclear and the question requires correction. I have nothing more to add. good luck - aleksandr barakin

1 answer 1

It is worth adding a slash to the first rule.

.gitignore:

 /*/ ; Игнорируем все папки !/Documents/ ; кроме Documents !/bin/ ; и bin 

Thus, files in the root will not be affected.