Search code examples
gitgit-submodulesgit-push

Pushing in submodule in git version 2


I'm using from git version 2.7.4, with submodules. My project structure is like this:

main/
   file1
   file2
   subm1/
       file3
       file4
   subm2/
       file5

According to this question I want to push in submodule. For example, after changing in file3, I'm using this commands to push it:

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

I have recieved this error:

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!

but when I use pull like this recieved Already up-to-date:

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

How can I push it into submodule origin repository?


Solution

  • My code was not in master branch, switching to master branch solve this issue.