1

I have a repo set up on github which already contains an existing project (For arguments sake, lets call this repo1).

In a separate repo (repo2) I have a subfolder which I've been using to create an updated version of the project in repo1.

Is there a way I can now push the working files on my local machine (which at the moment are setup to push to repo2), to repo1 and it will overwrite the existing project in there?

I hope that's clear and apologies if this is something straighforward to do!

Cheers

AndyBeable
  • 21
  • 3

1 Answers1

0

The simplest approach would be to opy the updated source to your local repository, add, commit, and push either in the default branch or in a separate branch of repo1.

But to your question:

  • change the remote repository URL of your local repository: from repo1 to repo2
  • move your history from root folder in your local repository to the matching subfolder from repo2, using git filter-repo (install it first)
  • merge --ours origin/main from repo2 to your main, making your local main branch
  • push

That is:

cd /path/to/local/repo
git remote set-url origin /url/repo2
git filter-repo --path-rename /:aSubFolder/ 
git fetch
git merge --ours origin/main
git push
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283