Submodule update when setting up multiple git accounts

I have two git identifiers, one personal, the other for my employer.

My work project uses a submodule, and although I can clone the main repo, I cannot update the submodule. What do I need to configure so that the submodule can also be updated locally without getting the following error?

Fetching origin From github.com:/work_domain/work_submodule * branch HEAD -> FETCH_HEAD error: pathspec 'master' did not match any file(s) known to git. 

I have 2 id_rsa key sets in the ~ / .ssh directory:

 id_rsa.pub <= personal ssh key id_rsa_work.pub <= work ssh key 

~ / .ssh / configuration file:

 #work acccount Host github-work HostName github.com User git (corrected with info from answers) IdentityFile ~/.ssh/ida_rsa_work #personal account Host github-personal HostName github.com User git Identity ~/.ssh/ida_rsa 

When I initially cloned my working repo, I used the configured host mapping:

 git clone git@github-work :work_domain/repo_name.git 

instead of what i usually use when at work:

 git clone git@github.com :work_domain/repo_name.git 

As part of the repo working draft, the .gitmodules file, of course, has an official display:

 [submodule "work_submodule"] path = work_submodule url = git@github.com :/work_domain/work_submodule.git 

Following the suggestion below, I updated the .gitmodules attribute:

 [submodule "work_submodule"] path = work_submodule url = git@github-work :/work_domain/work_submodule.git 

But so far it has not been possible to update the submodule locally.

+4
source share
2 answers

To prevent accidentally entering your private URL for the submodule into the repository (which depends on your .ssh/config ), you should instead change the URL in .git/ssh


Editing the URL in a .gitmodules file to use github-work is one way to do this. However, since this is the file part of the project, this can be done by mistake.

Instead, as @Chronical is mentioned in the comment. To change only the local settings for a particular check, you should change the URL in .git/config instead

 url = github-work:/work_domain/work_submodule.git 

By changing it there, and not in .gitmodules , you can get rid of the extra cleanup step that accidentally used the wrong URL

Note that if you do a git submodule sync URL, you are editing in .git/config , it will be rewritten with the address in .gitmodules

+2
source

Firstly, if you have ~ / .ssh / config, it should use different public / private keys, which means that your ssh-url should use the specified configuration file:

  url = github-work:/work_domain/work_submodule.git # or url = github-personal:/work_domain/work_submodule.git 

The whole point of the configuration file consists in using different keys and does not require mentioning the user, port number, server name, etc.
' github-work ' and ' github-personal ' are the input keys in this configuration file, they are not server names.

Secondly, after changing the URL in the .gitmodules file, remember to do:

  • completely delete the contents of your submodule if it has already been downloaded from the previous address:
  rm -Rf work_domain / work_submodule;  git checkout - work_domain / work_submodule
  • update this submodule again:
  git submodule sync
 git submodule update work_submodule
0
source

Source: https://habr.com/ru/post/1483967/


All Articles