Created
January 25, 2026 23:53
-
-
Save disouzam/6ad9c43e56add6c64988054e1f9a107f to your computer and use it in GitHub Desktop.
Get file URL in a git repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| function get_file_url() { | |
| repourl=$(echo "$(git config --get remote.origin.url)" | sed -e 's/git@/https:\/\//' -e 's/\.git$//') | |
| branch=$(git branch --show-current) | |
| relative_file_path=$(echo $1 | sed -e 's/\\/\//g') | |
| echo $repourl/blob/$branch/$relative_file_path | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use it
get_file_url {path relative to repo's root}Example:
Consider the following file:
https://github.com/disouzam/data-analysis-with-python-and-pandas-by-chris-bruehl-maven-analytics/blob/main/.vscode/launch.json
To get the URL in command line, you need:
get_file_url .vscode/launch.json # https://github.com/disouzam/data-analysis-with-python-and-pandas-by-chris-bruehl-maven-analytics/blob/main/.vscode/launch.jsonIf in Windows, add double quotes embracing relative file path: