Search code examples
gitgit-submodules

git add my remote for pushing submodule


I have a main app that stored in our git. Within that app we are using a third-party component that's hosted on github. We make numerous customizations to this component, and as such felt that to make updates easier, we should add the component as a submodule.

It was my understanding that by adding this component as a submodule, we would be able to pull upstream changes from github and merge those into our submodule. We would then push those changes to our git.

I successfully added the component as a submodule, and cloned it into my app's directory. I've merged in all our modifications, and committed those locally.

My question is, how do I now add our git as a remote for the submodule so that I can push all my customizations to that server?


Solution

  • Your submodule is just another git repo. The same steps for adding an additional remote and pushing the changes apply here as well.

    cd <DIRECTORY_OF_YOUR_SUBMODULE>
    git remote add <REMOTE-NAME> <PRIVATE_GIT_REPO_URL>
    git fetch <REMOTE-NAME>
    
    # Now you should be able to merge, rebase or cherrypick or any other
    # merge strategy you prefer.
    
    # After merging push the changes into your remote
    git push <REMOTE-NAME> <LIST_OF_REFS>