Is there a way to add a new file to all of my projects in my Git Repository at once?

Hi, I am trying to add a config file to all my projects in my Git repository.  I can do it one by one but I had more than 140 projects in my Git repo, which takes a lot of time to get that done, so I was trying to find a shorter way to add this file to all of my projects at once, is it possible? by writing any script?

Do you mean that you have a bunch of subdirectories under https://github.com/deepu558/some-repo-name that you want to add the same file to? Or do you mean that you have a bunch of repositories under https://github.com/deepu558 that you want to add the same file to?

I mean that I have a bunch of repositories under https://github.com/deepu558 that I want to add the same file to.

There isn’t a built-in way to do this on GitHub. When I’ve needed to do something like this, I’ve built a script to loop through all the repositories listed in a text file and perform the following with each:

  1. Clone the repository to my local machine if it doesn’t exist already
  2. Perform a git fetch
  3. Create a new branch based on the default branch
  4. Copy the file from a given location into the repository
  5. Commit the change
  6. Push the new branch to the remote repository
  7. Launch the link to create a new PR based on the new branch in my default browser
  8. Wait for me to press a key before moving to the next one

I posted a Ruby script that does a lot of the Git interactions to help get you started.

1 Like