Giter Site home page Giter Site logo

migrate-submodules's Introduction

Migrate Submodules

Git migrations tools like GitHub Importer and even ghe-migrator are not able to update submodule urls. This small script solves that problem by updating all your .gitmodules files recursively with a simple sed command.

Install

You can run this script in any git repository and it will recursively itterate submodules and perform the following operations:

  1. Executes the sed command provided via -s on .gitmodules
  2. Synchronizes submodules' remote URL configuration setting to the value specified in .gitmodules
  3. Updates(pulls) all submodules.
  4. Commits the changes to the branch provided via -b with the message provided via -m

NOTES

  • You must have read/write permission on the repositories you are modifying
  • This script will not import repositories for you and assumes all required repositories have already been imported to your target. This means if you are replacing the url of a submodule, the new URL must be pointing to a valid repository.

Usage ๐Ÿƒโ€โ™‚๏ธ

This example is migrating the url from bitbucket.org to github.com.

Clone your repo that contains submodules and cd inside:

git clone https://[email protected]/austenstone/main-test1.git
cd main-test1

Run the script:

migrate-submodules.sh -s 's/bitbucket.org/github.com/g' -b 'master'

Congratulations. Your submodules have been updated! ๐ŸŽ‰

Check them out ๐Ÿ‘€

cat .gitmodules && git submodule foreach --recursive '[ -f .gitmodules ] && cat .gitmodules || true'

If you are happy with the results, push your changes to remote:

git submodule foreach --recursive git push origin master
git push origin master

TIP: You can automatically sync all branches with master by running the following command:

for BRANCH in `ls .git/refs/heads`; do git rebase master $BRANCH; done
git push --all origin

To see this example in action read the GitHub Actions workflow and also checkout the previous runs.

Install โฌ‡๏ธ

Simply add the script to your PATH.

cd /usr/local/bin
curl https://raw.githubusercontent.com/austenstone/migrate-submodules/main/migrate-submodules.sh > migrate-submodules.sh
chmod +x migrate-submodules.sh

Script tested on Ubuntu and MacOS.

Test Repo Hierarchy

bitbucket.org/austenstone/main-test1 is the root of a small set of repos and is used to test the functionality.

github.com/austenstone/main-test1 is the migrated repo.

graph TD;
    main-test1-->child-test1;
    child-test1-->child-test1-child ;
    main-test1-->child-test2;
Loading

Possible Improvements ๐Ÿšง

  • Use set-url [--] <path> <newurl> instead of sed.
  • Sync all branches in the script
  • Dynamically get the default branch using git remote show origin | sed -n '/HEAD branch/s/.*: //p'

Inspiration โœจ

migrate-submodules's People

Contributors

austenstone avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.