Search code examples
gitmergegit-submodulespull

Git: Pull and Merge Questions


I'm following Git tutorials but I'm still not very clear about the Pull command and the effects on the remote and local repositories.

My two questions are the following:

Q1: Let's say I have a project with submodules 1 2 and 3, the local and remote repos are up to date. Now, a teammate changes submodule 3 on the remote repo. So now, the remote will be ahead by one commit.

  • If I decide to go into my local project and Pull. Will submodule 3 on my local repo be updated with the information that is on the repo? In other words, will it overwrite whatever is on my local repo with that information?

Q2:

  • If submodule 3, let's say has five files, and is is up to date with my local repo. And teammate deletes two files in the remote, leaving only three files on the remote repository.

If I then go into my local repo and Pull, will extra files on local be deleted so that it is up to date with what's on the remote, leaving a total of just three files?

Thanks


Solution

  • will it overwrite whatever is on my local repo with that information?

    It will update but not necessarily overwrite the content in your submodule 3 directory. If you have no local modifications, yes then git pull will update all files updated remotely. If you should have any files modified you will get a conflict (can be mitigated with git pull origin --rebase). In other words there is nothing special with this submodule repository, git pull behaves the same as everywhere.

    Where there is a difference though is that after you do a pull inside the submodule it will be marked as updated and dirty in the parent repository but it will not make any changes to the version it is linked to. To do that you need to explicitly from the parent repo do git add submodule3dir; git commit -m "Updated submodule 3 to latest version".

    In other words git pull inside a submodule will update your worktree, but it will not update your index and it will not create a corresponding commit. You need to explicitly run add and commit to do that.