I have two repositories on a local machine.
main-repo
sub-repo
I added the sub-repo as a submodule in main-repo. The sub-repo contains a readme file.
Originally, I kept the directory name the same as the repo name. I changed the sub-repo directory to sub1. Hopefully, that clears up any confusion.
main-repo
sub1
readme
If I made changes to readfile from the main-repo/sub-repo/readme, NOT from sub-repo/readme directly.
These are the steps I have done. Since this is only on my local machine, I added the submodule using this command
cd main-repo
git submodule add file:///c:/Users/Worker/Git/t5-sub/sub-repo sub1
cd main-repo/sub1
git checkout master
edit readme file
git commit.
git push
cd sub-repo directory
git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: readme
When I look at the content of readme file, it does not have the changes. How do pull the changes from main-repo to the sub-repo?
You shouldn't git push
at point 5 because you push to a non-bare repository which is not recommended. Actually I expect an error on such a push with message "remote: error: refusing to update checked out branch: refs/heads/master" .
You should pull to it, not push:
cd sub-repo
git remote add sub ../main-repo/sub1
git pull sub master
I have tried @phd suggestion. It did not work for me. After playing around a bit, I found this to work for me.
cd sub-repo
git restore --staged readme
git checkout .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.