Deleting Files in Git
Use git rm command to delete any file from current working directory. You also need to commit and push your changes to delete the file from the local and remote git repository.
git rm [filename]
For example, you have multiple files in your current project. In my case, the files are as followings.
ls -ltotal 164 drwxr-xr-x 2 root root 4096 Dec 28 03:29 Documents -rw-r--r-- 1 root root 35259 Dec 28 03:28 firstfile.txt -rw-r----- 1 root root 119180 Dec 28 03:28 general.log -rw-r--r-- 1 root root 47 Dec 28 03:27 README.md
Now, I am deleting the general.log file from the git repository. Change filename according to your deletion.
git rm general.logrm 'general.log'
After deleting the file, you have to commit your changes to local git repository using the following command. Change your commit message according to yours.
git commit -a -m "Removed log file"[master 5558666] Removed log file 1 file changed, 1068 deletions(-) delete mode 100644 general.log
Now push your changes, So that the file also get deleted from the remote git repository.
git push origin masterUsername for 'https://github.com': [GIT USERNAME] Password for 'https://[GIT USERNAME]@github.com': Counting objects: 2, done. Delta compression using up to 2 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 223 bytes | 0 bytes/s, done. Total 2 (delta 1), reused 0 (delta 0) remote: Resolving deltas: 100% (1/1), completed with 1 local object. To https://github.com/tecrahul/tecadmin.net 3d31ae3..5558666 master -> master