Terminal: how can I paste a file to all the subfolders within a directory?

Basically, I created a .gitignore file with the following content (ignore all the class files but do not .gitignore file):

# Ignore files below
*.class


# but not these files
!.gitignore

I want to propagate this to all sub-folders or even sub-sub-folders within the directory.

I know I can do it in the naive way by copying and pasting it manually.

But is there a better way to do this using a few commands in the terminal ?

  • git revert HEAD is opening the nano editor. How can I avoid this?
  • Error linking git to homebrew
  • Git commit message on linux terminal
  • Smart auto-completition for staged git file names, used with difftool
  • Do I Need to Run Git Init Multiple Times for Each Project I'm Working on?
  • Git setup, terminal returning : command not found
  • .gitignore doesn't stop changes being tracked in files
  • Git master home directory
  • 2 Solutions collect form web for “Terminal: how can I paste a file to all the subfolders within a directory?”

    You don’t have to (“propagate this to all sub-folders or even sub-sub-folders within the directory”):

    A .gitignore rule will be applied to all subfolders, unless another .gitignore rule (in one of the subfolders) override that rule.

    See Pro Git book gitignore section:

    Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file.

    find . -type d -print | xargs -L 1 cp .gitignore

    The find command prints out the name of all directories under . and including .

    The xargs command, with the -L 1 parameter, executes cp .gitignore <dir> for each directory found.

    You’ll see an error about not copying .gitignore onto itself in the current directory.

    Git Baby is a git and github fan, let's start git clone.