I have a local directory in which I have initialized git. I have added all files of that directory in git using:
git add *
Now if I delete a file manually from my local directory, I want to get it deleted from github too. I have tried
git add -A *
But it does not work. Everytime I have to delete it manually from github too.
Add All Files using Git Add. The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area.
gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file. You can omit the --cached option if you want to delete the file from both the repository and your local file system.
Hi@akhtar, The difference lies in which files get added. git add -A command will add all modified and untracked files in the entire repository. Whereas git add . will only add modified and untracked files in the current directory and any sub-directories.
Listing all the deleted files in all of git history can be done by combining git log with --diff-filter . The log gives you lots of options to show different bits of information about the commit that happened at that point.
The problem is that the glob (*
) is expanded by your shell, not git, and the shell does not know anything about the files that you have already deleted. git add -A
without any more arguments would add all the files, including deleted files. git add .
will also do this in the current git version. You could also use git rm --cached <file>
for individual files as suggested in other answers.
It's usually easier to just use git rm
to remove the files, as this will both remove the file AND stage the removal.
If you want to delete a file from your index you should use
git rm filename
Documentation can be found here: https://git-scm.com/docs/git-rm
An important note for this command is:
git rm will not remove a file from just your working directory. (There is no option to remove a file only from the working tree and yet keep it in the index; use /bin/rm if you want to do that.)
Let me know if it works!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With