Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting Files using Git/GitHub

Tags:

git

github

First off, I'm new to Git.

I deleted a bunch of files locally on my Mac using Finder. I want the files that I deleted to no longer show in the current branch, but they do.

Any Git users know a command to update the index?

like image 928
Zack Avatar asked Dec 31 '09 00:12

Zack


People also ask

How do I delete a file from github repository?

Browse to the directory in your repository that you want to delete. In the top-right corner, click , then click Delete directory. Review the files you will delete. At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file.

Can we delete file from Git repository?

The "rm" command helps you to remove files from a Git repository. It allows you to not only delete a file from the repository, but also - if you wish - from the filesystem. Deleting a file from the filesystem can of course easily be done in many other applications, e.g. a text editor, IDE or file browser.

What is the git command to delete a file?

The git rm command can be used to remove individual files or a collection of files. The primary function of git rm is to remove tracked files from the Git index. Additionally, git rm can be used to remove files from both the staging index and the working directory.


2 Answers

I think this would be a simpler way to do what you want:

git add . -A 

Then you would just do:

git commit -m "removed some files"

As noted above.

like image 166
Samuel Mikel Bowles Avatar answered Sep 18 '22 02:09

Samuel Mikel Bowles


You can see deleted files, which are still 'tracked' with:

git ls-files --deleted

To delete files from a branch, you can do something like this:

git ls-files --deleted -z | xargs -0 git rm

From man git-rm:

Remove files from the index, or from the working tree and the index. git-rm will not remove a file from just your working directory. (There is no option to remove a file 13 only from the work tree and yet keep it in the index; use /bin/rm if you want to do that.)

Finally, to commit the "removal" do something like:

git commit -m "removed some files"
like image 40
miku Avatar answered Sep 21 '22 02:09

miku