Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete files from git bare remote repository?

Tags:

git

git-remote

I have a remote bare git repository.

A new developer cloned it, but he didn't have a properly configured .gitignore file, so he mistakenly pushed some unwanted files into the remote. When I pulled the changes and merged, I got these previously untracked files. Others have also pulled the changes from the remote and have these unwanted files as well.

How do I delete these files from the remote repository, and everyone else's remote/origin/branches?

like image 690
Stuarty Avatar asked Sep 07 '12 03:09

Stuarty


People also ask

How do I remove files from a remote git repository?

The easiest way to delete a file in your Git repository is to execute the “git rm” command and to specify the file to be deleted. Note that by using the “git rm” command, the file will also be deleted from the filesystem.

How do I remove a file from my git repository without deleting locally?

Using the git rm –cached Command We've mentioned that git rm FILE will remove files from the index and local working tree by default. However, the git rm command provides the –cached option to allow us only to remove files from the repository's index and keep the local file untouched.

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.

How do I remove data from my 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.


1 Answers

See github have a FAQ on this: https://help.github.com/articles/remove-sensitive-data Here are the steps:

  1. Rewrite the tree from local (working) tree.

    $ git filter-branch --index-filter 'git rm --cached --ignore-unmatch Rakefile' \ --prune-empty --tag-name-filter cat -- --all

  2. Force push to remote.

    $ git push origin master --force

  3. Everybody pull from the remote (and use --force if needed)

To prevent this from happening again, you should check the .gitignore in the repository (and optionally setup a hook on server)

like image 112
J-16 SDiZ Avatar answered Oct 08 '22 19:10

J-16 SDiZ