Remove a file from git Repository

Sometimes a file may contain sensitive data like an API key and you may want to remove this file from the git repository. Let us see how can we achieve that in this article.

Use git rm:

git rm file1.txt
git commit -m "remove file1.txt"

But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:

git rm --cached file1.txt
git commit -m "remove file1.txt"

And to push changes to remote repo

git push origin branch_name

Source : https://stackoverflow.com/questions/2047465/how-can-i-delete-a-file-from-git-repo