Skip to content

Instantly share code, notes, and snippets.

@disouzam
Created January 25, 2026 18:01
Show Gist options
  • Select an option

  • Save disouzam/fe3416fcc7734900f1b697c5091c81f5 to your computer and use it in GitHub Desktop.

Select an option

Save disouzam/fe3416fcc7734900f1b697c5091c81f5 to your computer and use it in GitHub Desktop.
Get commit remote URL via command line using Bash
#!/bin/bash
function get_commit_url() {
echo "$(git config --get remote.origin.url)" | \
sed -e 's/git@/https:\/\//' -e 's/\.git$//' \
| awk -v sha="$(git rev-parse $1)" '{print $0"/commit/"sha}'
}
@disouzam
Copy link
Author

I got the code for this Gist from someone over StackOverflow. Unfortunately, I didn't keep track of the source.

@disouzam
Copy link
Author

How to use it

When in a git repo in your computer, execute the commands below:

get_commit_url {commit-hash}

Example:

Consider this commit: https://github.com/gvwilson/sim/commit/0f3ca1f35b34d374d727b558ee4633b35bd6a5df

get_commit_url 0f3ca1f35b34d374d727b558ee4633b35bd6a5df
# https://github.com/gvwilson/sim/commit/0f3ca1f35b34d374d727b558ee4633b35bd6a5df
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment