diff --git a/get-modified-packages/README.md b/get-modified-packages/README.md
index ca350687..0e00193b 100644
--- a/get-modified-packages/README.md
+++ b/get-modified-packages/README.md
@@ -4,13 +4,15 @@ This action get the list of ROS packages modified in the pull request.
 
 ## Usage
 
+### Basic
+
 ```yaml
 jobs:
   get-modified-packages:
     runs-on: ubuntu-latest
     steps:
       - name: Check out repository
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
         with:
           fetch-depth: 0
 
@@ -19,6 +21,27 @@ jobs:
         uses: autowarefoundation/autoware-github-actions/get-modified-packages@v1
 ```
 
+### Fetch only the PR branch and all PR commits
+
+```yaml
+jobs:
+  get-modified-packages:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Set PR fetch depth
+        run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"
+
+      - name: Checkout PR branch and all PR commits
+        uses: actions/checkout@v4
+        with:
+          ref: ${{ github.event.pull_request.head.sha }}
+          fetch-depth: ${{ env.PR_FETCH_DEPTH }}
+
+      - name: Get modified packages
+        id: get-modified-packages
+        uses: autowarefoundation/autoware-github-actions/get-modified-packages@v1
+```
+
 ## Inputs
 
 | Name        | Required | Description                                      |
diff --git a/get-modified-packages/action.yaml b/get-modified-packages/action.yaml
index beef4b4b..10d5b2ab 100644
--- a/get-modified-packages/action.yaml
+++ b/get-modified-packages/action.yaml
@@ -2,7 +2,7 @@ name: get-modified-packages
 description: ""
 
 inputs:
-  base-branch:
+  base-ref:
     description: ""
     required: false
     default: ${{ github.base_ref }}
@@ -20,10 +20,16 @@ runs:
         git config --global --add safe.directory "$GITHUB_WORKSPACE"
       shell: bash
 
+    - name: Fetch the base branch with enough history for a common merge-base commit
+      run: |
+        git fetch origin ${{ inputs.base-ref }}
+      shell: bash
+
     - name: Get modified packages
       id: get-modified-packages
       run: |
-        echo "modified-packages=$(${GITHUB_ACTION_PATH}/get-modified-packages.sh origin/${{ inputs.base-branch }})" >> $GITHUB_OUTPUT
+        modified_packages=$(${GITHUB_ACTION_PATH}/get-modified-packages.sh origin/${{ inputs.base-ref }})
+        echo "modified-packages=$modified_packages" >> $GITHUB_OUTPUT
       shell: bash
 
     - name: Show result
diff --git a/get-modified-packages/get-modified-packages.sh b/get-modified-packages/get-modified-packages.sh
index a9522dd8..834115f5 100755
--- a/get-modified-packages/get-modified-packages.sh
+++ b/get-modified-packages/get-modified-packages.sh
@@ -2,8 +2,6 @@
 # Search for packages that have been modified from the base branch.
 # Usage: get-modified-packages.sh <base_branch>
 
-set -e
-
 # Parse arguments
 args=()
 while [ "${1-}" != "" ]; do
@@ -15,6 +13,7 @@ while [ "${1-}" != "" ]; do
     shift
 done
 
+# example: base_branch="origin/main"
 base_branch="${args[0]}"
 
 # Check args
@@ -49,8 +48,11 @@ function find_package_dir() {
     return 1
 }
 
-# Find modified files from base branch
-modified_files=$(git diff --name-only "$base_branch"...HEAD)
+# Find modified files from the base branch
+if ! modified_files=$(git diff --name-only "$base_branch"...HEAD); then
+    echo -e "\e[31mFailed to determine modified files. Please check if the base branch exists and fetch depth is sufficient.\e[m"
+    exit 1
+fi
 
 # Find modified packages
 modified_package_dirs=()