0

I want to be able to do the following:

$ pwd
/tmp/repo

$ ls -l
/a-dir
/another-dir
.gitignore
a-file
another-file

$ git add -A
<< ONLY .gitignore, a-file and another-file are added >>

How can I achieve that?

NOTE: More files and directories could be added as time goes on. The directories, and all of their contents should be ignored. Only the files residing in the repositories root directory should be included.

EDIT: I want to do this with the .gitignore file, so I don't have to remember to run a different command each time. I just want to keep it simple with git add -A, and have the .gitignore take care of it.

Jack_Hu
  • 857
  • 6
  • 17
  • Does this answer your question? [How to \`git add\` non-recursively?](https://stackoverflow.com/questions/30663402/how-to-git-add-non-recursively) – Renat Mar 11 '20 at 15:06
  • Sorry, I've updated the question to clarify a bit more exactly what I'm after. – Jack_Hu Mar 11 '20 at 15:09

1 Answers1

1

I had exactly the same requirements as you at some point, and my .gitignore looks like this:

# Ignore all subdirectories
/*/

# Keep a specific subdirectory
!/foo/

# .gitignore as usual
.vs/
.int/
.out/
*.user
Quentin
  • 62,093
  • 7
  • 131
  • 191