Reputation: 31
I have a repo that has over 300 branches, and I am wanting to store various files on in a Git LFS. To do this I need to add the .gitattributes
file to the branches first. However, as I have over 300 branches, manually doing this will be very time consuming.
Is there a way that I can add a prepopulated .gitattributes
file to the root of every branch automatically and push them?
Upvotes: 1
Views: 625
Reputation: 4580
A one-liner which assumes you have a branch named feature/add-gitattributes
which makes the necessary changes;
git for-each-ref refs/remotes/origin --format="%(refname:lstrip=3)" | xargs -n 1 sh -c 'git checkout "$1"; git merge feature/add-gitattributes;' --
To break it down...
This part just gets a list of those 300 branch names;
git for-each-ref refs/remotes/origin --format="%(refname:lstrip=3)"
This part takes those names and passes them to a sub-shell;
| xargs -n 1 sh -c
This part is the command to the sub-shell which checks out the target branch and merges your feature branch to add the .gitattributes
file.
'git checkout "$1"; git merge feature/add-gitattributes;' --
The trailing --
ensures the branch name is passed as an argument to the sub-shell.
Upvotes: 1