diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index ff6f8156abbba5f22cca30a699ff7ba40e3dd4bf..d9ff880e5ee0ffc5b9a741c4ccfa02dbedf14bf5 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -23,7 +23,7 @@ repos:
     rev: 3.8.4
     hooks:
     - id: flake8
-      entry: bash -c 'git diff $CI_MERGE_REQUEST_TARGET_BRANCH_SHA | flake8 --diff' --
+      entry: bash -c 'if [ -z ${CI_MERGE_REQUEST_TARGET_BRANCH_SHA} ]; then (flake8 "$@"); else (git diff $CI_MERGE_REQUEST_TARGET_BRANCH_SHA | flake8 --diff); fi' --
   - repo: https://github.com/myint/rstcheck
     rev: 3f92957478422df87bd730abde66f089cc1ee19b  # commit where pre-commit support was added
     hooks: