<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>simonh.uk - vcs</title><link href="https://simonh.uk/" rel="alternate"></link><link href="https://simonh.uk/feeds/vcs.atom.xml" rel="self"></link><id>https://simonh.uk/</id><updated>2026-06-21T00:00:00+01:00</updated><subtitle>Simon Harrison :: Burton on Trent :: UK</subtitle><entry><title>Update Multiple Git and Mercurial repositories with Python</title><link href="https://simonh.uk/2026/06/21/update-multiple-git-and-mercurial-repositories-with-python/" rel="alternate"></link><published>2026-06-21T00:00:00+01:00</published><updated>2026-06-21T00:00:00+01:00</updated><author><name>Simon Harrison</name></author><id>tag:simonh.uk,2026-06-21:/2026/06/21/update-multiple-git-and-mercurial-repositories-with-python/</id><summary type="html">	&lt;p&gt;Git / HG updater script&lt;/p&gt;</summary><content type="html">	&lt;p&gt;&lt;img alt="Python Logo" src="/img/logo/python.svg" title="Python Logo" /&gt;&lt;/p&gt;

	&lt;p&gt;I have quite a few downloaded repositories that I keep on my local machine. Most are versioned with Git (obviously) and I was after a way to update them all via a script. After searching on the internet for a bit and not finding anything I was happy with, I decided to write my own in Python. &lt;/p&gt;

	&lt;p&gt;I have my downloaded Git repos in the following directory structure:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[simon@computer 17:14:32] ~/repo/got
$ tree -L 1
.
├── alpine.git
├── apache
├── breezy.git
├── bsd
├── debian
├── edit.git
├── epr.git
├── fdm.git
├── fizzy.git
├── gnu
├── got.git
├── got-portable.git
├── image-blob-reduce.git
├── lr.git
├── mblaze.git
├── micro.git
├── nanorc.git
├── nq.git
├── odftoolkit.git
├── OpenSMTPD.git
├── pdftk.git
├── perl
├── python
├── qbe.git
├── ruby
├── rwc.git
├── scc.git
├── src.git
├── superdoc.git
├── sysvinit.git
├── treq.git
├── trix.git
├── wcal.git
├── wfm.git
└── xe.git&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The script will update each repository using Got for Git repo&amp;#8217;s and Mercurial for Mercurial repo&amp;#8217;s. Subdirectories (apache, gnu, python, ruby etc.) will also be updated. &lt;/p&gt;

	&lt;p&gt;In the future I might add error checking and a timeout for repositories that hang, but as it is currently, the script works fine for my needs. &lt;/p&gt;

	&lt;h2&gt;update-repos.py&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;#!/usr/bin/python3
# v0.2

import os

got_dir = &amp;#39;/home/simon/repo/got&amp;#39;
hg_dir = &amp;#39;/home/simon/repo/hg&amp;#39;

def update_got():
    print(&amp;#39;\nUpdating Git Repositories...&amp;#39;)
    for i in os.listdir(got_dir):
        if i.endswith(&amp;#39;.git&amp;#39;):
            os.system(f&amp;#39;got fe -r {os.path.join(got_dir, i)}&amp;#39;)
        else:
            print(f&amp;#39;\n\n*** Updating subdirectory: {i} ***\n\n&amp;#39;)
            for s in os.listdir(os.path.join(got_dir, i)):
                os.system(f&amp;#39;got fe -r {os.path.join(got_dir, i, s)}&amp;#39;)

def update_hg():
    print(&amp;#39;\n\nUpdating Mercurial Repositories...\n\n&amp;#39;)
    for i in os.listdir(hg_dir):
        os.system(f&amp;#39;hg pull -R {os.path.join(hg_dir, i)}&amp;#39;)

update_got()
update_hg()&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;And that&amp;#8217;s it. Twenty lines of Python and ten minutes work! Feel free to adapt it to your needs. If you prefer Git, change the got fetch line to:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;os.system(f&amp;#39;git pull -r {os.path.join(got_dir, i)}&amp;#39;)&lt;/code&gt;&lt;/pre&gt;</content><category term="vcs"></category><category term="vcs"></category><category term="python"></category><category term="mercurial"></category><category term="tips"></category></entry></feed>