Loading...
Loading...
GitLab repository file operations via API. ALWAYS use this skill when user wants to: (1) read file content from GitLab, (2) create/update/delete files via API, (3) get file blame info, (4) download raw files.
npx skill4agent add grandcamel/gitlab-assistant-skills gitlab-fileglab api| Operation | Command Pattern | Risk |
|---|---|---|
| Get file info | | - |
| Get raw content | | - |
| Get blame | | - |
| Create file | | ⚠️ |
| Update file | | ⚠️ |
| Delete file | | ⚠️⚠️ |
api%2F# src/main.py -> src%2Fmain.py
echo 'src/main.py' | jq -Rr @uri
# Output: src%2Fmain.py# Get file metadata and content (base64)
glab api "projects/123/repository/files/README.md?ref=main" --method GET
# With URL-encoded path
glab api "projects/123/repository/files/$(echo 'src/main.py' | jq -Rr @uri)?ref=main"
# From specific branch
glab api "projects/123/repository/files/config.json?ref=develop" --method GET
# From tag
glab api "projects/123/repository/files/version.txt?ref=v1.0.0" --method GET
# From commit SHA
glab api "projects/123/repository/files/app.py?ref=abc123" --method GETfile_namefile_pathsizeencodingcontentcontent_sha256refblob_idcommit_idlast_commit_id# Get and decode file content
glab api "projects/123/repository/files/README.md?ref=main" | \
jq -r '.content' | base64 -d# Get raw file content (not base64)
glab api "projects/123/repository/files/README.md/raw?ref=main" --method GET
# With encoded path
glab api "projects/123/repository/files/$(echo 'src/app.py' | jq -Rr @uri)/raw?ref=main"
# Binary file (save to file)
glab api "projects/123/repository/files/$(echo 'images/logo.png' | jq -Rr @uri)/raw?ref=main" > logo.png# Get blame information
glab api "projects/123/repository/files/$(echo 'src/main.py' | jq -Rr @uri)/blame?ref=main" --method GET
# Parse blame output
glab api "projects/123/repository/files/$(echo 'src/main.py' | jq -Rr @uri)/blame?ref=main" | \
jq -r '.[] | "\(.commit.author_name): lines \(.lines | length)"'# Create new file with content
glab api "projects/123/repository/files/$(echo 'docs/new-file.md' | jq -Rr @uri)" --method POST \
-f branch="main" \
-f content="# New File\n\nContent here" \
-f commit_message="Add new documentation file"
# Create with base64 content
glab api "projects/123/repository/files/$(echo 'data/config.json' | jq -Rr @uri)" --method POST \
-f branch="main" \
-f content="$(cat config.json | base64)" \
-f encoding="base64" \
-f commit_message="Add configuration file"
# Create on new branch
glab api "projects/123/repository/files/$(echo 'feature/new.txt' | jq -Rr @uri)" --method POST \
-f branch="feature-branch" \
-f start_branch="main" \
-f content="Feature content" \
-f commit_message="Add feature file"
# Create with author info
glab api "projects/123/repository/files/script.sh" --method POST \
-f branch="main" \
-f content="#!/bin/bash\necho Hello" \
-f commit_message="Add script" \
-f author_email="dev@example.com" \
-f author_name="Developer"# Update file content
glab api "projects/123/repository/files/README.md" --method PUT \
-f branch="main" \
-f content="# Updated README\n\nNew content here" \
-f commit_message="Update README"
# Update with base64 (for binary or complex files)
glab api "projects/123/repository/files/$(echo 'config/settings.json' | jq -Rr @uri)" --method PUT \
-f branch="main" \
-f content="$(cat settings.json | base64)" \
-f encoding="base64" \
-f commit_message="Update settings"
# Update on feature branch
glab api "projects/123/repository/files/src%2Fapp.py" --method PUT \
-f branch="feature-update" \
-f content="$(cat app.py | base64)" \
-f encoding="base64" \
-f commit_message="Refactor app module"
# Update with last known commit (for conflict detection)
glab api "projects/123/repository/files/data.json" --method PUT \
-f branch="main" \
-f content="{ \"updated\": true }" \
-f commit_message="Update data" \
-f last_commit_id="abc123def456"# Delete file
glab api "projects/123/repository/files/$(echo 'old-file.txt' | jq -Rr @uri)" --method DELETE \
-f branch="main" \
-f commit_message="Remove deprecated file"
# Delete with author info
glab api "projects/123/repository/files/$(echo 'temp/test.txt' | jq -Rr @uri)" --method DELETE \
-f branch="main" \
-f commit_message="Clean up temp files" \
-f author_email="dev@example.com" \
-f author_name="Developer"| Option | Type | Description |
|---|---|---|
| string | Target branch (required for write ops) |
| string | Source branch for new files |
| string | File content (plain text or base64) |
| string | Content encoding: |
| string | Commit message (required for write ops) |
| string | Custom author email |
| string | Custom author name |
| string | Expected last commit (for conflict detection) |
# Get file content
glab api "projects/123/repository/files/$(echo 'config/app.yml' | jq -Rr @uri)/raw?ref=main"# 1. Download current file
glab api "projects/123/repository/files/config.json/raw?ref=main" > config.json
# 2. Edit locally
# ... make changes to config.json ...
# 3. Upload updated file
glab api "projects/123/repository/files/config.json" --method PUT \
-f branch="main" \
-f content="$(cat config.json | base64)" \
-f encoding="base64" \
-f commit_message="Update configuration"# Create new file on new branch
glab api "projects/123/repository/files/$(echo 'docs/feature.md' | jq -Rr @uri)" --method POST \
-f branch="feature-docs" \
-f start_branch="main" \
-f content="# Feature Documentation\n\nDetails here..." \
-f commit_message="Add feature documentation"# Get blame info for a file
glab api "projects/123/repository/files/$(echo 'src/critical.py' | jq -Rr @uri)/blame?ref=main" | \
jq -r '.[] | "\(.commit.short_id) \(.commit.author_name): \(.lines | length) lines"'# Read multiple files
for file in "README.md" "package.json" "Dockerfile"; do
echo "=== $file ==="
glab api "projects/123/repository/files/$(echo "$file" | jq -Rr @uri)/raw?ref=main"
echo ""
done# 1. Get file from source branch
content=$(glab api "projects/123/repository/files/config.json/raw?ref=develop")
# 2. Create/update on target branch
echo "$content" | base64 > /tmp/content.b64
glab api "projects/123/repository/files/config.json" --method PUT \
-f branch="main" \
-f content="$(cat /tmp/content.b64)" \
-f encoding="base64" \
-f commit_message="Sync config from develop"| Issue | Cause | Solution |
|---|---|---|
| 404 Not Found | File doesn't exist | Verify path and branch |
| 400 Path encoding | Slashes not encoded | Use |
| Binary content garbled | Not using base64 | Use |
| Conflict on update | File changed | Use |
| 403 Forbidden | No push access | Need Developer+ role |
| Large file fails | Size limit | GitLab has file size limits |
last_commit_id