简体   繁体   中英

Push Submodule to GitHub

I have a problem pushing all code to GitHub after installing a component using composer. Here's the current setup:

  1. GitHub repository created.
  2. Repository cloned on local and project files added.
  3. There is one remote called "origin".
  4. Component added using "composer require". Component installed successfully to project sub-folder.
  5. Composer created a git submodule (in this sub-folder) with two remotes. (a) "origin" which points to the component author github url. (b) "composer" which points to the same url and does not have a push url.
  6. Project pushed to GitHub successfully but does NOT push git submodule containing component files.
  7. If I try to push component to project "origin" I get error "Updates were rejected because the remote contains work that you do not have locally".

How do I get this git submodule component code into my GitHub repo? The folder in GitHub is empty.

Make sure you're properly added the files to the stage area and committed them. Then you could try to push again:

git add . #to add all files to stage
git commit -m "Your commit message here"
git push origin master #if master is your branch

Once you've said that the repository in GitHub is empty, you could try a force push :

git push --force origin master

Also, sometimes, there is a tiny delay between the push and the files become available in GitHub.

Additionally, you could verify if the changes were correctly sent to GitHub by checking the differences between branches:

git diff --name-status master..origin/master

Digging deeper, I found the component had installed itself as a git submodule. I've updated the question to reflect that. A standard git push didn't deploy it to github. I probably needed to do a "git push --recurse-submodules=on-demand" (or similar).

But to keep things simple, I decided to remove the submodule. It was necessary to run the following to remove the submodule reference.

git rm --cached [path to submodule]

Also, installed.json showed the "installation-source" = source. Other modules had value dist. So I deleted all component files and ran the following to force composer to install a component dist.

composer require [component] --prefer-dist
composer install --prefer-dist

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM