Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update a git repo containing a submodule?

After some time I wanted to update my git repo, and then something went wrong. What is the proper way out of this situation?

mblsha@siruba:~/src/psi/ $ git status
iris: needs merge
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   src/common.cpp
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#
#   unmerged:   iris
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   gupdate.sh
mblsha@siruba:~/src/psi/ $ git submodule status
+cf237ef8f3d9dc058dbde47e6973e6388608ce60 iris (heads/master)
+cf237ef8f3d9dc058dbde47e6973e6388608ce60 iris (heads/master)
+cf237ef8f3d9dc058dbde47e6973e6388608ce60 iris (heads/master)
mblsha@siruba:~/src/psi/ $ cd iris 
mblsha@siruba:~/src/psi/iris/ $ cat .git/HEAD 
cf237ef8f3d9dc058dbde47e6973e6388608ce60
like image 302
mblsha Avatar asked Nov 10 '08 17:11

mblsha


People also ask

How do I update a specific submodule?

In order to update an existing Git submodule, you need to execute the “git submodule update” with the “–remote” and the “–merge” option. Using the “–remote” command, you will be able to update your existing Git submodules without having to run “git pull” commands in each submodule of your project.

Where do I update git submodule?

If you want to check for new work in a submodule, you can go into the directory and run git fetch and git merge the upstream branch to update the local code. Now if you go back into the main project and run git diff --submodule you can see that the submodule was updated and get a list of commits that were added to it.

How do I update a submodule in git recursive?

If you already cloned the project and forgot --recurse-submodules , you can combine the git submodule init and git submodule update steps by running git submodule update --init . To also initialize, fetch and checkout any nested submodules, you can use the foolproof git submodule update --init --recursive .

Will git pull update submodules?

Once you have set up the submodules you can update the repository with fetch/pull like you would normally do. To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .


2 Answers

When it comes to git submodules, almost any problem you encounter can be solved by:

1. deleting the submodule (rm -r iris)
2. recreating it again (git submodule update)

Obviously if you have made local changes to your submodule this will DELETE them PERMANENTLY, so if you have local changes make sure you have pushed them first.

like image 116
Daniel Lucraft Avatar answered Nov 01 '22 05:11

Daniel Lucraft


I posted a similar question here on stackoverflow and ended up answering it myself, but I found that using git reset HEAD iris worked for my issue with submodule conflicts.

like image 40
Tyler Avatar answered Nov 01 '22 04:11

Tyler