6

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?

pants
  • 192
  • 13
Stuarty
  • 278
  • 4
  • 13

2 Answers2

7

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)

J-16 SDiZ
  • 26,473
  • 4
  • 65
  • 84
2

This is a three step process:

  1. Remove the files from your copy of the repository (either with git rm or by totally purging these files from your history depending on how important it was that these files never be in the repository in the first place)
  2. Push your changes back to the remote repository using git push --force.
  3. Let everyone know that they can re-pull the repository - this will require a git rebase of their work on the last know good commit.

As a last step you may also want to add the .gitignore file to the repository so that when the repository is cloned all the right files get ignored.

Sean Vieira
  • 155,703
  • 32
  • 311
  • 293