1

Is there a way to remove a directory from every branch in a repo? I know I could manually (one at a time) check out each branch, delete the directory and its files, commit, push and then repeat for each branch.

I would prefer to have one command (or script) that can do this across all the branches of the repo.

Is this possible?

Don Rhummy
  • 24,730
  • 42
  • 175
  • 330

1 Answers1

3

There is nothing built in, but the plumbing command git for-each-ref allows you to iterate over all branch names:

git for-each-ref --format '%(refname:short)' refs/heads

Using this you can write a simple script that will git checkout each branch, git rm the file or files in question, and git commit the result. (You can then push all the results in one git push: there's no need to push each one as you go.)

Community
  • 1
  • 1
torek
  • 448,244
  • 59
  • 642
  • 775