rsync git modified files with awk and sed Feb 15

Need to rsync modified files to a server? Try the following:

All you need to do is ensure that the base path set properly and modify the portion of the script and you’re all set!

Explanation after the break.

Here’s the breakdown:

Display modified files the same way svn status does – line by line with a symbol in front to designate type of change.

  git status -s

This prints out the following:

 M www/path/to/file
 M www/another/path/to/file

Piped with the git call above, this will strip out everything fron the line except for the file path.

  awk '{print $2}'

This prints out the following:


With the file paths piped in via the awk command, add the rsync around it with sed.

  sed 's/\(.*\)/rsync -cav \1\/\1/'

This prints out the following:

  rsync -cav www/path/to/file
  rsync -cav www/another/path/to/file

Finally, we pipe the sed call into sh which executes it.