Created
February 23, 2026 06:52
-
-
Save HarHarLinks/8f86c51c460efbcf9d32adeb789d0587 to your computer and use it in GitHub Desktop.
Some functions for .bashrc/.zshrc to make working with PRs from forks easier
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
| gco-pr(){ | |
| git fetch origin pull/$1/head:$1 && git checkout $1 | |
| } | |
| gp-pr(){ | |
| branch="$(git branch --show-current)" | |
| remote_organisation="$(echo "$1" | sed 's/:.*//')" | |
| remote_branch="$(echo "$1" | sed 's/.*://')" | |
| origin="$(git remote get-url origin)" | |
| if [[ "$origin" == "git@"* ]]; then | |
| # parse ssh remote | |
| host="$(echo "$origin" | sed -E 's/git@([^:]+):([^\/]+)\/(.+)\.git/\1/')" | |
| organisation="$(echo "$origin" | sed -E 's/git@([^:]+):([^\/]+)\/(.+)\.git/\2/')" | |
| repo="$(echo "$origin" | sed -E 's/git@([^:]+):([^\/]+)\/(.+)\.git/\3/')" | |
| echo git push "git@$host:$remote_organisation/$repo.git" "$branch:$remote_branch" | |
| git push "git@$host:$remote_organisation/$repo.git" "$branch:$remote_branch" | |
| else | |
| # parse https remote | |
| host="$(echo "$origin" | sed -E 's/https:\/\/([^/]+)\/([^\/]+)\/(.+)\.git/\1/')" | |
| organisation="$(echo "$origin" | sed -E 's/https:\/\/([^/]+)\/([^\/]+)\/(.+)\.git/\2/')" | |
| repo="$(echo "$origin" | sed -E 's/https:\/\/([^/]+)\/([^\/]+)\/(.+)\.git/\3/')" | |
| echo git push "https://$host/$remote_organisation/$repo.git" "$branch:$remote_branch" | |
| git push "https://$host/$remote_organisation/$repo.git" "$branch:$remote_branch" | |
| fi | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I should probably mention that gco-pr takes the PR number as argument and gp-pr takes the remote user and branch separated by a colon which is what you get when you click the copy button next to the source branch name when viewing a GitHub PR.