Ryan Prentiss
Ryan Prentiss

Reputation: 1642

Remote Git repo is out of sync with local repo

I've noticed my remote repo contains many files which have been long deleted from my local repo. How do I correct this syncing issue?

I've attempted the following to correct:

  1. git add --all, then pushed. It did not work. Old files remain on remote repo.
  2. Created a new branch using git branch my-new-branch, then pushed. It did not work. The old files, which are not available locally, still pushed to new branch.
  3. Updated .gitignore to include .env file, then pushed. It did not work. The .gitignore file updates, although the .env file still exist on remote repo.

If I create a new file, push to remote, delete locally, then push again, the file will be deleted remotely. For some reason this seems to only be occurring with older files.

Upvotes: 0

Views: 975

Answers (1)

Tasnuva Leeya
Tasnuva Leeya

Reputation: 2795

you should remove git cache

git rm -r --cached .

then push back to the remote

$ git add .
$ git commit -am 'Removed files from the index (now ignored)'
$ git push

edit: to remove remote files, pull the changes from the server, do a git rm on your local repo, commit the changes, and push to the server. The files will be deleted. Don't forget to check whether you have duplicate folder or not.

Upvotes: 1

Related Questions