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.
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 usegit 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
Documentation can be found here: https://git-scm.com/docs/git-rm
An important note for this command is:
Let me know if it works!
You should use the "git rm" command.
git rm /path/to/file
ex: go to your git directory and type
git rm file.txt
Then do a git commit say:
git commit -m "Removing file"
Finally push your changes to your git repository. The file will now be removed from your repository too once you push these changes.
This earlier post on stack overflow gives more information: Git: why the file deletion does not sync?
Hope this helps!
The only thing you have to do is when removing files from local repository, rather than manually deleting the file from the local repository use,
or
After that, commit the change locally and push it. It should reflect in both local and remote repository.
Or if you have already manually deleted the files in the local repository and now if you want to remove from the remote repository as well, use
--cached
attribute. That is,or
Now if you have manually deleted files and want that reflect in both local and remote git repository, use,
Hope this helps! :)