As a developer, you constantly need paths relative to your Git repo root — for git add commands, PR descriptions, documentation, and CI scripts. The problem: macOS gives you absolute paths, which include your personal home directory and the full folder structure up to the file.
Every time you copy a path from Finder or Terminal, you end up doing mental subtraction: strip the repo prefix, keep only what comes after it. Do that twenty times a day and it adds up to a real friction tax on your workflow.
Install Pathly → right-click any file inside a Git repo → choose Copy Git Path. Pathly auto-detects the .git root and hands you the correct relative path instantly. $4.99 one-time on the Mac App Store.
Method 1: One Right-Click with Pathly (Recommended)
Pathly is a macOS Finder Extension that adds Copy Git Path directly to the right-click context menu. No Terminal, no configuration, no modifier keys.
Right-click any file or folder inside your Git repository in Finder.
Choose Copy Git Path from the menu.
The git-relative path (e.g., src/components/Button.tsx) is on your clipboard, ready to paste.
Pathly walks up the directory tree to find the nearest .git folder or file (it supports worktrees and submodules too) and computes the relative path from there. No setup required.
Pathly finds the nearest .git folder or .git file, so it correctly handles Git submodules and git worktree setups where the .git is a file pointing to the main repo.
Method 2: Terminal One-Liners
If you're comfortable in the shell, these commands give you git-relative paths without any additional tools.
Get the relative path of a specific file
# Returns the file's path relative to the repo root
git ls-files --full-name path/to/your/file.txt
# Example output:
src/components/Button.tsx
Get the relative prefix of your current directory
# Prints the path from repo root to current dir (with trailing slash)
git rev-parse --show-prefix
# Example: if you're in /Users/alex/projects/app/src
# Output: src/
Copy git-relative path directly to clipboard
# Combine with pbcopy to copy straight to clipboard
git ls-files --full-name Button.tsx | pbcopy
Create a zsh/bash alias for speed
# Add to ~/.zshrc or ~/.bash_profile
alias gpath='git ls-files --full-name'
# Usage:
gpath src/components/Button.tsx
# Output: src/components/Button.tsx
If the file isn't tracked by Git yet (new, untracked), git ls-files --full-name returns nothing. In that case, compute it manually: realpath --relative-to="$(git rev-parse --show-toplevel)" yourfile.txt
Method 3: Code Editors (VS Code, Cursor, Zed)
Most modern editors detect the Git root automatically and can copy the workspace-relative path directly from the file explorer.
VS Code / Cursor
- Right-click any file in the sidebar.
- Choose Copy Relative Path (or press ⌥⌘C).
- The path is relative to the workspace root, which is typically the repo root.
Zed
- Right-click a file in the Project panel.
- Choose Copy Relative Path.
These editor methods work great when you're already in the editor. But they don't help you when you need the path while you're in Finder, Terminal, or a chat window — which is where Pathly fills the gap.
Why Git Relative Paths Matter
- Commit messages — Reference the exact file that changed: "Fix null check in
src/utils/validate.ts" - PR descriptions — Link reviewers directly to the file: "See
docs/api/auth.mdfor the updated spec" - CI/CD configs — Paths in GitHub Actions, CircleCI, and Dockerfile must be repo-relative
- Documentation — READMEs and wikis reference files by their repo-relative path, not by who checked it out
- Cross-machine portability —
/Users/alex/projects/app/README.mdbreaks on your team's machines;README.mdnever does
Method Comparison
| Method | Speed | Works in Finder | Git-aware | Extra setup |
|---|---|---|---|---|
| Pathly (right-click) | Instant | ✓ Yes | ✓ Yes | None |
git ls-files --full-name |
Fast | ✕ Terminal only | ✓ Yes | Terminal open |
| VS Code / Cursor right-click | Fast | ✕ Editor only | ✓ Yes | Editor open |
| Manual path editing | Slow | ✓ Yes | ✕ Manual | None (error-prone) |
Stop computing relative paths by hand. Get all five path formats — including Git — in one right-click.
Get Pathly — $4.99Frequently asked questions
What is a git-relative path?
A git-relative path is the path to a file relative to the root of a Git repository. For example, if your repo root is /Users/alex/projects/app and the file is at /Users/alex/projects/app/src/Button.tsx, the git-relative path is src/Button.tsx.
How do I get a git-relative path on Mac without extra tools?
In Terminal, use: git ls-files --full-name yourfile.txt. This returns the file's path relative to the repo root. For the current directory prefix, use git rev-parse --show-prefix.
Does Pathly work with Git submodules and worktrees?
Yes. Pathly walks up the directory tree looking for a .git folder or a .git file (which is how Git submodules and git worktree setups work). It uses whichever .git it finds first as the repo root.
What if the file isn't tracked by Git yet?
Pathly computes the relative path based on the directory structure, not on whether the file is tracked. So it works on untracked new files, ignored files, and any file inside a directory that contains a .git folder.