Solving Git Submodule Error In Foundry Project: 'git submodule exited with code 1 | 128'

Swooping through the new Patrick Collins Smart Contract Foundry course with a froggy drive only to get stuck on an error git submodule exited with code 1". or `git submodule exited with code 128`

Well, let's get fixxy...🥂

Replicating The Error

The error is generated from trying to install packages from your `lib` folder in your Foundry project.

I encountered this error last year while trying to follow through a foundry course online, only to have the same error in a new project I'm working on.

Try cloning a foundry project from GitHub for example: `git clone git@github.com:Phenzic/3-passwordstore-audit.git`.

You'll notice the empty library folders inside your lib folder

The command command forge install should install all the packages instead you're left with the error message: git submodule exited with code 1

Or try installing one of the packages like forge install Openzeppelin/openzeppelin-contracts --no-commit you'll get the error message: git submodule exited with code 128

Solving the Error

As an alternative solution, I tried installing the packages directly using git, although this works fine and solves the problem, I'm not exactly sure if it is recommended.

Steps to installing packages in foundry

  1. cd into your lib directory

  2. run the command git clone <link to git package on github> for example. git clone git@github.com:OpenZeppelin/openzeppelin-contracts.git

  3. Head over to the foundry.toml file in your default project directory to add mapping the newly installed packages, like so.

    
     "remappings": [
       "@prb/test/=lib/prb-test/src/",
       "ds-test/=lib/forge-std/lib/ds-test/src/",
       "forge-std/=lib/forge-std/src/",
       "prb-test/=lib/prb-test/src/",
       "@opensezppling/=lib/openzeppelin-contracts/"
     ],
    

here are other options for editing the foundry.toml file.

I'd love to connect with you on Twitter | LinkedIn | GitHub | Portfolio

If you find this solution helpful, follow for more technical blog posts

2
Subscribe to my newsletter

Read articles from Mayowa Ogungbola directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mayowa Ogungbola
Mayowa Ogungbola

Hi I'm Phenzic I simply wanna help you transition into web3 seamlessly...