From my experience, the most straightforward way to git delete file
is using git rm
. This command does two things—it deletes the file from your working directory and stages it for deletion in your next commit. So, here’s what you’d run:
git rm file1.txt
git commit -m "Remove file1.txt from repo"
That’s all there is to it! This tells Git you’re intentionally removing the file, and it reflects in your commit history cleanly. It’s especially helpful if you’re collaborating with others because it keeps things traceable and clear.