0

I've got a question.

I want to remove all of the files from remote that are not in current commit. e.i. clean the remote to current commit.

Example:

Local Host: 
Directory:
 - folder 1
 -- file 1
 -- fiel 2  
 - folder 2
 -- file 1 

Remote: 
Directory:
 - folder 1
 -- file 1
 -- fiel 2  
 - folder 2
 -- file 1 
 - folder 3
 -- file 1
 -- fiel 2  

Such that I would delete anything that is not in on my local host, not in my commit. In this case Folder 3 and files would be deleted from remote.

Vadim Osipov
  • 41
  • 1
  • 5
  • Are you trying to scrub the history of your repo, to remove traces of previously existing files in there? If so, this might help: https://stackoverflow.com/q/43762338/3216427 – joanis Jun 12 '21 at 18:18
  • Note that Git does not *store* files; as such, you can't have it *remove* files either. Git stores *commits* (which then in turn store files, but you have to operate on things commit by commit). – torek Jun 13 '21 at 05:42

1 Answers1

1

The only way you could arrive at your current working directory which is sans a "folder 3" would be if you deleted that folder in the current commit, or some previous commit. When you push your commit(s), you are also pushing the instruction to delete "folder 3" on the remote.

In case you are still in doubt, the remote file structure just reflects whatever the structure is in the HEAD or latest commit. If "folder 3" be not present there, then it will not show up on the remote.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • That's absolutely correct. But, for some reason my automated commits do not remove the `deleted` files on remote. So in example I get 5 working directories on local, and 10 directories(new and old ones) on remote. – Vadim Osipov Jun 12 '21 at 15:55