One-liners for mass-updating you local git projects

Posted in category shell on 2017-06-23
Tags: shell, bash, linux

If you are like me, sometimes you need to update all you repositories somewhere in ~/Projects folder. And it is best to be automated. So, if you are on Linux you can try commands I am going to show here.

Example here would be to update paket.dependencies and paket.lock files in each and every repository, then commit and push this change. Here is how easy it is to do it:

cd ~/Projects
find -type f -name paket.dependencies -exec sed -i 's/version1/version2/' {} \;
find -type f -name paket.lock -exec sed -i 's/version1/version2/' {} \;
find -maxdepth 1 -regex '..+' -type d \
  -exec bash -c "cd {}; git commit -am 'Upgrade packageA'; git push" \;

A little -regex '..+' is there just to get rid of one single result that find produces - . folder which in this case corresponds to current ~/Projects folder.

Happy hacking!