Is it possible to remove all files in a repository and update it with only the files I have in my local machine? The reason is that, there are certain files that is not necessar
Do a git add -A
from the top of the working copy, take a look at git status
and/or git diff --cached
to review what you're about to do, then git commit
the result.
First of all, Navigate to your Folder using cd ( change directory) command. Then make sure you are in the correct git branch which you want to work by using the command
git branch
If you want to delete the entire files. you can do the same by using
git rm -r .
for deleting a single file,
git rm file1.txt
( file1.txt - file Name )
for delete a folder,
git rm -r foldername
After deleting the files or folders, you should commit it:
git commit -m "your comment"
Then you can push the branch:
git push
// for example,
git push origin develop
(it will update the origin repository)
I have tried like this
git rm --cached -r * -f
And it is working for me.
Yes, if you do a git rm <filename>
and commit & push those changes. The file will disappear from the repository for that changeset and future commits.
The file will still be available for the previous revisions.
You could do it like this:
cd /tmp
git clone /your/local/rep # make a temp copy
cd rep
git rm -r * # delete everything
cp -r /your/local/rep/* . # get only the files you want
git add * # add them again
git status # everything but those copied will be removed
git commit -a -m 'deleting stuff'
cd /your/local/rep
git pull /tmp/rep # now everything else has been removed
There's probably a oneliner for that…
Remove all files not belonging to a repositiory (e.g. for a clean-build after switching a branch):
git status | xargs rm -rf