Automatically update all your git files with this Ruby script!
Ever spent neglected to update your git files because there were too many to deal with? My cool coworker Tom Czarniecki showed me this cool script that allows him to update all his git files at once. Here’s how it works!
Step 1: the Ruby script
Open your text editor of choice, create a new file, and save it as gitupdatescript.rb
(or another filename of your choice) in the root of your folder containing git files. Copy and paste the following code into the file:
#!/usr/bin/env ruby
require 'fileutils'
Dir.glob('**/.git').each do |path|
next if File.file?(path) # don't process submodules
start_time = Time.now
project_base = File.expand_path("#{path}/..")
puts "In #{project_base}"
FileUtils.cd(project_base) do
system('git stash')
puts "Update failed" unless system('git pull --rebase')
system('git stash pop')
end
end_time = Time.now
puts "Done in #{end_time - start_time} sec"
puts
end
Step 2: turn the file into an executable
We’ll now be using the command line to allow this file to modify our computer’s files. I use a Mac, so please be sure to translate to other languages as needed (and let me know if it works!). cd
to the folder containing the ruby file we created and enter the following code:
chmod +x gitupdatescript.rb
If your ruby file is located elsewhere, include the path to the file in your command.
Step 3: execute your new script
To run your script, just type ./gitupdatescript.rb
and it should start updating git files!
Upcoming talks
-
Moving from execution to strategy presentation + Staff Designer workshop
I'll be delivering a presentation called "Moving from execution to strategy as a designer" and a workshop designed to help very senior designers identify and navigate the roadblocks that keep most seasoned individual contributor designers from getting to the next level. Join me in Seattle — or virtually — for a deep dive into career growth!
Want to talk?
Got feedback, looking to suggest a future writing topic, or want to invite me to speak at your organization? Send me a message and I'll get back to you as soon as possible!