1

There is one thing I want: the latest bits of the remote master. This is equally true for the for the sub-modules. I'm not interested in any other branch or history. Any change made locally irrespective whether these changes are tracked or not should be blindly ditched.

So, here is my shot on this, formulated as part of a Makefile. It is quite slow (lots of/large files) and it fails some times. Please let me know how to improve it:

pull: $(LOCAL_REPO)
    cd $(LOCAL_REPO) && git submodule foreach git fetch origin master
    cd $(LOCAL_REPO) && git submodule foreach git reset --hard FETCH_HEAD
    cd $(LOCAL_REPO) && git submodule foreach git clean -fdx
    cd $(LOCAL_REPO) && git submodule foreach git pull --rebase --allow-unrelated-histories origin master --depth 1
    cd $(LOCAL_REPO) && git fetch origin master
    cd $(LOCAL_REPO) && git reset --hard FETCH_HEAD
    cd $(LOCAL_REPO) && git clean -dfx
    cd $(LOCAL_REPO) && git pull --rebase --allow-unrelated-histories origin master --depth 1

$(LOCAL_REPO):
    mkdir -p $(LOCAL_REPO)
    cd $(LOCAL_REPO) && git init
    cd $(LOCAL_REPO) && git remote add origin $(PRIVATE_GITHUB_GIT)
    cd $(LOCAL_REPO) && git pull origin master --depth 1
    cd $(LOCAL_REPO) && git submodule init $(SUBMOD1) $(SUBMOD2) $(SUBMOD3)
    cd $(LOCAL_REPO) && git submodule update --remote --merge --depth 1
  • Why would you init a repo each time ? If a remote already exists, why not clone instead ? – nquincampoix Dec 15 '22 at 14:39
  • @nquincampoix: "make pull" runs only the first block if the $(LOCAL_REPO) folder exists. – icecream notebook Dec 15 '22 at 15:10
  • What part do you think runs slowly? The `pull` target, that's obvious, but what command(s) in the target? – phd Dec 15 '22 at 17:37
  • Does this answer your question? [Pull latest changes for all git submodules](https://stackoverflow.com/questions/1030169/pull-latest-changes-for-all-git-submodules) combined with [How do I force "git pull" to overwrite local files?](https://stackoverflow.com/questions/1125968/how-do-i-force-git-pull-to-overwrite-local-files?rq=1) – Inigo Dec 17 '22 at 15:21

0 Answers0