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.

  • how can I create git branch like develop/user1/issue1
  • How to determine latest production release from a git master branch?
  • Git: “could not read from remote repository”, when remote is another local repo
  • Making vim show a git diff with colors like a git diff command (red-delete, green-add)
  • How to add a git repository as a shared dependency of another git repository?
  • Passing a list of arguments to docker at build / run time
  • 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 ?

  • “HEAD not found below refs/heads” after I push commit with CR/CRLF changes
  • Git push --force from IntelliJ IDEA
  • Syncing two GIT branches that only differ by a couple of files
  • Git Version numbering with a centralized workflow
  • Git Update Hook: Finding all files being pushed to a new branch
  • Git: show all commits on a given weekday
  • 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.