Skip to content

Instantly share code, notes, and snippets.

@clementi
Last active March 17, 2026 19:19
Show Gist options
  • Select an option

  • Save clementi/9691b28b6c3a8f935e0f74a83e8974ff to your computer and use it in GitHub Desktop.

Select an option

Save clementi/9691b28b6c3a8f935e0f74a83e8974ff to your computer and use it in GitHub Desktop.
#!/usr/bin/env runhaskell
import System.Process ( readProcess )
import System.Environment ( getArgs )
import Control.Monad (forM_)
main :: IO ()
main = do
branch <- head <$> getArgs
let repos = [ "repo1"
, "repo2"
, "repo3" ] -- Replace with your own repo names
forM_ repos (updateRepo branch)
-- Update the repo at `repo` with an empty commit on the branch `branch`
updateRepo :: String -> String -> IO String
updateRepo branch repo = do
let path = repoPath repo
_ <- runGit path ["checkout", "master"]
_ <- runGit path ["pull", "--rebase"]
_ <- switchToBranch path branch
_ <- runGit path ["pull", "--rebase"]
_ <- runGit path ["commit", "--allow-empty", "-m", "commit message"] -- Put your commit message here
runGit path ["push", "-u", "origin", branch]
-- Get the path of the repo specified by `repo`
repoPath :: String -> String
repoPath repo = "/homedir/" <> repo -- Replace with your home directory, e.g., "/Users/me/projects/"
-- Switch to a branch in the repo at `path`. Creates the branch if it does not exist.
switchToBranch :: String -> String -> IO String
switchToBranch path branch = do
branches <- getBranches path
if branch `elem` branches then
runGit path ["checkout", branch]
else
runGit path ["checkout", "-b", branch]
-- Get the branches of a repo at `path`
getBranches :: String -> IO [String]
getBranches path = fmap words (readProcess "git" ["-C", path, "branch"] "")
-- Run git with `args` in the working directory at `path`
runGit :: String -> [String] -> IO String
runGit path args =
readProcess "git" (["-C", path] <> args) ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment