Don Rhummy
Don Rhummy

Reputation: 25830

How remove directory/files from all branches in a repo? (as new commit in each)

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?

Upvotes: 1

Views: 960

Answers (1)

torek
torek

Reputation: 488193

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.)

Upvotes: 3

Related Questions