How to delete file and folder from git repo


To delete files and folders from a Git repository, follow these steps:

  1. Open a terminal or command prompt.

  2. Navigate to the local Git repository on your computer using the cd command. For example:

cd /path/to/your/repo
  1. To delete a file, use the git rm command followed by the file name. For example:
git rm file-to-delete.txt
  1. To delete a folder, use the git rm command with the -r flag followed by the folder name. For example:
git rm -r folder-to-delete
  1. After deleting the files or folders, commit the changes with a commit message. For example:
git commit -m "Removed unwanted files and folders"
  1. Finally, push the changes to the remote repository. For example:
git push origin main

Replace main with the name of the branch you are working on if it’s different.

Note: This process will only delete the files and folders from the Git repository, not from your local file system. If you want to delete them from your local file system as well, you’ll need to do that manually.


Author: robot learner
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source robot learner !
  TOC