Make change to a git submodule, and keep the changes

I’ve cloned a git submodule of one of my libraries into a project I’m working on. The thing is that, after cloning, I need to change some lines in the cloned submodule, but I don’t want to push those changes into the original repository.

I want those changes to stay in the superproject. Is this possible? How can I achieve that?

  • Redo merge of just a single file
  • Hanging at “POST git-receive-pack (chunked)”
  • Import history from renamed files and folders to version control
  • How do I copy a version of a single file from one git branch to another?
  • Git Revert Not Working
  • Why Does My BASH Script Fail When Adding Additional Arguments?
  • EDIT: As @GoZoner said, basically its:

    1. git clone foo;
    2. cd foo;
    3. git submodule init;
    4. git submodule update;
    5. cd path/to/submodule;
    6. git checkout master;
    7. Make changes to the submodule
    8. git commit -am “Something”;
    9. git push origin (the superproject);

    Then when I clone the superproject in another computer (up to step 4), I want those changes to be saved, in the superproject.

  • How to merge develop branch to master branch within SourceTree?
  • Force git to run post-receive hook, even if everything is “up-to-date”
  • If you delete a git branch do it's commits go with it?
  • Failed to connect to repository : Error performing command: git.exe ls-remote -h HEAD
  • Tortoise Git side-by-side with Tortoise SVN?
  • How to merge/pull from remote repository
  • 2 Solutions collect form web for “Make change to a git submodule, and keep the changes”

    I think you need to relax the ‘no commit to submodule’ constraint. There are two options:

    1. Commit your submodule changes to a submodule branch. It is your team’s branch and it is where your team put your submodule changes. When somebody clones the super project and updates the submodule they get the content of your team’s branch.
    2. Clone the submodule repository ‘right next to’ your super project repository and initialize the submodule to point to your clone. Then when you commit changes to the submodule they are committed to your clone. Anybody who clones the super project gets submodule content from your submodule clone.

    Otherwise, I don’t see a way to achieve your desire.

    You can checkout a separate branch for your changes. Don’t push that branch up. Changes that you do want to push, make that on one of the original branches. Merge that branch into your special branch that you don’t push up. Don’t do any other work on your special branch as you would then have to merge the other way. You can do that but it gets complicated.

    Git Baby is a git and github fan, let's start git clone.