52

I'm attempting to use git-filter-repo to remove large binaries from my repository. I have not used python before. I installed the latest python by clicking on the downloaded .exe file as that is a requirement of git-filter-repo. The instructions say:

git-filter-repo is a single-file python script, which was done to make installation for basic use trivial: just copy it into your $PATH

https://github.com/newren/git-filter-repo/#how-do-i-install-it

I have tried opening the git-filter-repo.py with the python application. I also can't use cd, ls, or dir in the python application.

CBFT
  • 733
  • 1
  • 5
  • 9
  • 2
    The repo's INSTALL.md says to use your package manager, and lists a version for Ubuntu 20.04. I tried APT with no luck. – ndemarco Jul 06 '21 at 15:21
  • For Windows installation, [these steps may help](https://stackoverflow.com/a/69356543/184546). – TTT May 20 '22 at 21:22

4 Answers4

54

pip install

They now have a python package that just works:

python3 -m pip install --user git-filter-repo

That method installs both the command line executable, and the Python library which you can use as shown here.

The executable is named git-filter-repo, and Git automatically picks up any executable in PATH with name git-* on calls like git *, which is how this works.

Alternatively, if for some reason you don't want to use pip, you can also:

# Add to bashrc.
export PATH="${HOME}/bin:${PATH}"

mkdir -p ~/bin
wget -O ~/bin/git-filter-repo https://raw.githubusercontent.com/newren/git-filter-repo/7b3e714b94a6e5b9f478cb981c7f560ef3f36506/git-filter-repo
chmod +x ~/bin/git-filter-repo

Tested on Ubuntu 20.04, git-filter-repo ac039ecc095d.

  • 3
    I installed the package with pip in windows, but still get "git: 'filter-repo' is not a git command." – krenkz Oct 06 '20 at 18:01
  • 1
    @krenkz hi, this describes how Git finds stuff: https://gitirc.eu/howto/new-command.html Can you make sure that `git-filter-repo` it is either on `PATH`, or manually create a symlink in `git -exec-path` as mentioned at: https://superuser.com/a/1563783/128124 ? In Linux it just works because it goes to `PATH`. – Ciro Santilli OurBigBook.com Oct 06 '20 at 19:25
  • 1
    I eventually just added git-filter-repo's location to the PATH and changed its first line to '#!/usr/bin/env py' and now it works fine - all done manually. Thanks! – krenkz Oct 06 '20 at 20:08
  • `git filter-repo` is a `git` command that tries to execute `git-filter-repo`. This will look for `git-filter-repo` in your `$PATH` (and other usual suspects?). Installing with `pip` may not put `git-filter-repo.py` into a place where `git` looks or may not make it executable. – CervEd Sep 26 '21 at 18:27
  • @CervEd do share OS and OS version if you came across a system where that happens – Ciro Santilli OurBigBook.com Sep 26 '21 at 19:15
  • @CiroSantilli新疆再教育营六四事件法轮功郝海东 just pointing why one might get `git: filter-repo is not a git command`. It depends on how `git`, `python` and how the system in general is configured. – CervEd Sep 26 '21 at 19:32
  • @CervEd I understand, I'm not doubting it, just if you find any concrete examples of such systems, it might be good to mention them to give them more visibility – Ciro Santilli OurBigBook.com Sep 26 '21 at 20:24
  • @CiroSantilli新疆再教育营六四事件法轮功郝海东 I can add that installing `git-filter-repo` on windows using `chocholately` requires admin privledges – CervEd Sep 26 '21 at 20:28
17

On a Mac, you can install it using homebrew:

$ brew install git-filter-repo

ronen
  • 271
  • 2
  • 3
10

This is how I got it to work.

  1. Python should be installed and added to the system's path.
  2. Git should be installed and git also added to the system's path.
  3. Download git-filter-repo
  4. Replace 'python3' on first line of file called git-filter-repo with 'python'. Depending on your python installation, you may skip this step.
  5. Call git --exec-path
  6. Move the git-filter-repo file into that location shown. (git's path).
  7. To use, type git filter-repo. The help option will not work, but they have documentation online.
CBFT
  • 733
  • 1
  • 5
  • 9
3

On a Mac, I simply downloaded https://github.com/newren/git-filter-repo/blob/main/git-filter-repo into my ~/local/bin (which was already on my path and where I keep all my batch files etc). After chmod +x git-filter-repo, I just ran it from my repo dir like: git-filter-repo --path mydir.

DrGo
  • 131
  • 1