Rafael Wörner
Rafael Wörner

Reputation: 319

Deleted local files automatically remove from git repo?

When I delete files in my local working directory and make a git add . git commit and finally git push the files are just in the remote repo and in the working directories of other people pulling my commit.

Is there a way besides git rm for every single file, to tell git to delete those files everywhere (remote repo and in the working directories of the others)?

Upvotes: 1

Views: 918

Answers (2)

user663031
user663031

Reputation:

Use the -u option to git add to stage removal of deleted files.

git add -u

From the manpage:

--update

Only match <filepattern> against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed.

If no <filepattern> is given, default to "."; in other words, update all tracked files in the current directory and its subdirectories.

As @farzad describes, if you then commit and push, then anyone pulling the latest version of the branch will see the relevant files deleted.

Upvotes: 3

farzad
farzad

Reputation: 8855

If the files are under version control by git (not in the excluded list), then you'd better use proper git command to remove the files:

 git rm filename
 git commit -m "removed filename because of the reason"
 git push

This will remove the file from version control, so after this anyone that pulls will have that file removed.

Upvotes: 2

Related Questions