Skip to content
Easy rewrite of git submodule urls
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Easy rewrite of git submodule urls


  • Rewrite submodule urls using Extended Regular Expressions (sed -r)
  • Recursive rewrite (-r) for big submodule hierarchies


$ git submodule-url-rewrite -h
usage: git submodule-url-rewrite [-h|--help] [-v|--verbose] [-q|--quiet] [-r|--recursive] [-s|--no-stage] [-u|--no-update] sed-command

Rewrites all submodule urls using the given sed-script

  -h|--help       Print this help
  -v|--verbose    Make this script verbose
  -q|--quiet      Don't print anything
  -r|--recursive  Also rewrite submodules of submodules
  -s|--no-stage   Don't stage changed .gitmodule files for commit
  -u|--no-update  Don't run 'git submodule --quiet update --init' in each submodule

sed-command: A sed command used to transform urls.


Clone Enteee/example-dependency

$ git clone
Cloning into 'example-dependency'...
remote: Enumerating objects: 39, done.
remote: Counting objects: 100% (39/39), done.
remote: Compressing objects: 100% (30/30), done.
remote: Total 39 (delta 5), reused 39 (delta 5), pack-reused 0
Unpacking objects: 100% (39/39), done.

The .gitmodules file points to githubtraining/example-submodule.git

$ cat example-dependency/.gitmodules
[submodule "js"]
  path = js
  url =

Rewrite that to point to the repository Enteee/example-submodule.git:

$ git -C example-dependency/ submodule-url-rewrite 's|githubtraining|Enteee|'
rewrite url for submodule 'js' in '/tmp/example-dependency' from '' to ''


Installation of the command is as simple as copying the script somewhere to your ${PATH} and making it executable.

$ cd /usr/local/bin
$ curl \
  --output git-submodule-url-rewrite \
$ chmod a+x git-submodule-url-rewrite
You can’t perform that action at this time.