From 734517991a32842696a1272f23cb610cb2d1a4a3 Mon Sep 17 00:00:00 2001 From: Frank Fesevur Date: Fri, 1 Dec 2017 22:41:32 +0100 Subject: [PATCH] Update support for open.default.remote config (#79) --- README.md | 10 ++++++++++ git-open | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ad9aebe..e0e6ba9 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,16 @@ If your Gitlab custom hosted is serving `http` you can also specify this: git config [--global] gitopen.gitlab.protocol http ``` +### Default remote + +Normally `git open` opens the remote named `origin`. When you fork a project +and add a remote named `upstream` you often want that upstream to be opened +as the default remote. To accomplice this, you can do this: + +```sh +git config open.default.remote upstream +``` + ## Alternative projects See [hub](https://github.com/github/hub) for complete GitHub opening support. diff --git a/git-open b/git-open index 553855b..d952c3a 100755 --- a/git-open +++ b/git-open @@ -41,10 +41,12 @@ if ! git rev-parse --is-inside-work-tree &>/dev/null; then exit 1 fi -# choose remote. priority to: provided argument, detected tracked remote, 'origin' +# choose remote. priority to: provided argument, default in config, detected tracked remote, 'origin' branch_name=$(git name-rev --name-only HEAD 2>/dev/null) tracked_remote=$(git config "branch.$branch_name.remote") -remote=${1:-$tracked_remote} +default_remote=$(git config open.default.remote) +remote=${1:-$default_remote} +remote=${remote:-$tracked_remote} remote=${remote:-"origin"} # @TODO ls-remote will also expand "insteadOf" items `giturl=$(git ls-remote --get-url $remote)``