在 git 版本 2 中推送子模块

Pushing in submodule in git version 2

我使用的是 git 版本 2.7.4,带有子模块。我的项目结构是这样的:

main/
   file1
   file2
   subm1/
       file3
       file4
   subm2/
       file5

根据 this question 我想推入子模块。例如,更改 file3 后,我使用此命令推送它:

cd subm1/
git add file3
git commit -m 'Update file3'
git push origin master

我收到这个错误:

Pushing submodule 'subm1'
To <submodule git repo>
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to <submodule git repo>
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Unable to push submodule 'subm1'
fatal: Failed to push all needed submodules!

但是当我像这样使用 pull 时收到 Already up-to-date:

subm1$ git pull origin master 
From https://gitlab.com/systemnegar-ai/compare
 * branch            master     -> FETCH_HEAD
Already up-to-date.

如何将其推送到子模块原始存储库?

我的代码不在master分支,切换到master分支解决这个问题。