首页 > 解决方案 > 在 git 子模块中推送更改

问题描述

我在子模块 repo 中推送更改时遇到问题。

add submodule add https://github.com/ikalnytskyi/termcolor.git
git add .
git commit -m "Add the new color submodule"

之后,我对termcolor子模块进行了一些更改

cd termcolor
echo Hello>>hello.txt
git add .
git commit -m "Add hello.txt"

最后,我想将这个提交推送到我的远程仓库,但我认为 git 想要这个子模块仓库的登录名和密码,当然,我不知道。

git push origin master
Username for 'https://github.com': lyalival
Password for 'https://lyalival@github.com': 
remote: Invalid username or password.    

那么,问题来了,为什么 git 不把它推送到我的项目仓库呢?

PS 例如,在我的主文件夹中,我推送更改而不写登录名和密码,我只是输入

git push origin master

标签: gitgit-submodulesgit-push

解决方案


最后我解决了。我认为 git 在我的存储库中添加了本地副本,但事实并非如此。

所以,如果我想更改子模块,我需要创建一个新项目,然后

cd submodule
git remote set-url origin [link_to_my_project]

然后我能够

git push origin master

推荐阅读