Implementation of GitHub Repo as a Submodule in your project

Himanshu Kesharwani
3 min readMay 17, 2023

--

Introduction

Git Submodule is a feature in Git that allows you to include a repository within another repository as a subdirectory. It enables you to manage dependencies and include external code repositories in your project.

In the context of Swift, you can use Git Submodules to incorporate external Swift packages or libraries into your Swift projects. By adding a Git Submodule, you can easily integrate third-party code, track its changes, and manage its versions within your main project.

Add a Git Submodule in Swift

To add a git submodule in an iOS project, you can follow these steps:

  1. Open the Terminal app on your Mac.
  2. Navigate to the root directory of your iOS project in the Terminal.
  3. Run the following command to add a submodule:

4. After running the above command, navigate to the local path where the submodule was added.

5. Run the following command to check out the submodule:

6. Open your Xcode project and add the submodule files to your project:

  • In the Xcode Navigator, right-click on your project’s folder and select “Add Files to ‘Project Name’”.
  • In the file selection dialog, navigate to the local path of the submodule and select all the files you want to add to your project.
  • Click “Add” to add the selected files to your project.

After following these steps, you should have successfully added a git submodule to your iOS project. You can now use the submodule code in your project by importing the necessary files and classes.

To Updated Code for a submodule

To get updated code for a submodule in your Git repository, you can follow these steps:

  1. Open the Terminal or command prompt.
  2. Navigate to the root directory of your project that contains the submodule.
  3. Run the following command to fetch the latest changes from the submodule repository:

4. This command updates the submodule to the latest commit available in its repository. If there are any changes, it will fetch and apply them in your project.

5. After running the command, navigate to the submodule directory within your project.

6. If necessary, you can switch to a specific branch or commit of the submodule by using the following commands:

or

By following these steps, you can get the updated code for a submodule in your Git repository and integrate it into your project.

It’s a wrap 🎁

Congratulation, you learned the basics of Git Submodule. Happy Coding 🎉

Feel free to add me on github, or LinkedIn if you have any questions.
My Git-Hub Repo link for GitHub-Submodule.

--

--

Himanshu Kesharwani
Himanshu Kesharwani

No responses yet