Skip to content

Instantly share code, notes, and snippets.

@markwragg
Last active February 7, 2023 13:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markwragg/857d8a1151ebf1f0afcdb3f6fb930c5a to your computer and use it in GitHub Desktop.
Save markwragg/857d8a1151ebf1f0afcdb3f6fb930c5a to your computer and use it in GitHub Desktop.
A PowerShell function to open the remote URL in the default browser for the git repo folder you are currently in at the command-line.
function Open-GitUrl {
$RemoteURL = git config remote.origin.url
if ($RemoteURL) {
if ($RemoteURL -match '\.git$') { $RemoteURL = $RemoteURL -replace '\.git$','/' }
if ($IsMacOS) {
open $RemoteURL
}
else {
start $RemoteURL
}
}
else {
Write-Warning 'Could not retrieve remote.origin.url. Are you in a git folder?'
}
}
'ogu','ogh','github'| ForEach-Object { Set-Alias $_ Open-GitUrl }
@famatas
Copy link

famatas commented Feb 7, 2023

Thank you!

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