How can I delete files from the local (localhost) and remote (Bitbucket) repository, but save them on the production server after executing the git pull command?

I decided to reduce the size of the repository. I put the file in .gitignore, then I do

git rm --cached --force <FILE_NAME> git commit -ma 'COMMIT_NAME' git push 

I go to the production-server, I do

 git pull 

and the files are deleted there too.

How to avoid it?

  • one
    Due to the fact that you delete a file in a particular commit, the size of the repository will not decrease. Why do you need git on the production server? It's safe? - mymedia

1 answer 1

To save the files you have to switch to the commit where they are on the server, copy these files to another folder, switch to the commit where they are no longer there and copy back.

But reducing the size of the repository will not help.

The only way to reduce the size is to edit all the commits in the history where these files were, by deleting them. Then rub the history on the server. Update on all local copies. And run git gc. Attention! after work gc is no longer possible to return!