From 8e026276968d6a5bd0c2c5e13add05a955931442 Mon Sep 17 00:00:00 2001 From: Samxamnam Date: Sat, 24 Aug 2024 15:41:41 +0200 Subject: [PATCH] Remote argument for publish and unpublish --- doc/examples/index.md | 4 ++-- doc/git-publish/index.md | 8 ++++++-- doc/git-unpublish/index.md | 7 ++++++- gitalias.txt | 4 ++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/doc/examples/index.md b/doc/examples/index.md index d1296963..fc88f46b 100644 --- a/doc/examples/index.md +++ b/doc/examples/index.md @@ -135,9 +135,9 @@ Publishing: Git alias: ```git -publish = "!git push -u origin $(git current-branch)" +publish = "!f() { git push -u ${1:-origin} $(git current-branch); }; f" -unpublish = "!git push origin :$(git current-branch)" +unpublish = "!f() { git push ${1:-origin} :$(git current-branch); }; f" ``` Branching: diff --git a/doc/git-publish/index.md b/doc/git-publish/index.md index 2b7ee5a4..68e9168d 100644 --- a/doc/git-publish/index.md +++ b/doc/git-publish/index.md @@ -5,16 +5,20 @@ Git alias: ```git -publish = !"git push --set-upstream origin $(git current-branch)" +publish = "!f() { git push --set-upstream ${1:-origin} $(git current-branch); }; f" ``` -Publish the current branch by pushing upstream to origin, +Publish the current branch by pushing to the remote specified by the first argument (defaulting to origin), and setting the current branch to track the upstream branch. Example: ```shell +# pushing to origin git publish + +# pushing to fork +git publish fork ``` Compare: diff --git a/doc/git-unpublish/index.md b/doc/git-unpublish/index.md index 2b09cb74..ebe06b4f 100644 --- a/doc/git-unpublish/index.md +++ b/doc/git-unpublish/index.md @@ -5,16 +5,21 @@ Git alias: ```git -unpublish = !"git push origin :$(git current-branch)" +unpublish = "!f() { git push ${1:-origin} :$(git current-branch); }; f" ``` Unpublish the current branch by deleting the remote version of the current branch. +The remote name may be specified by the first argument and defaults to `origin`. Example: ```shell +# unpublish on origin git unpublish + +# unpublish branch on fork +git unpublish fork ``` Compare: diff --git a/gitalias.txt b/gitalias.txt index 719011d3..6c29072c 100644 --- a/gitalias.txt +++ b/gitalias.txt @@ -1372,11 +1372,11 @@ # Publish the current branch by pushing it to the remote "origin", # and setting the current branch to track the upstream branch. - publish = "!git push --set-upstream origin \"$(git current-branch)\"" + publish = "!f() { git push --set-upstream \"${1:-origin}\" \"$(git current-branch)\"; }; f" # Unpublish the current branch by deleting the # remote version of the current branch. - unpublish = "!git push origin :\"$(git current-branch)\"" + unpublish = "!f() { git push \"${1:-origin}\" :\"$(git current-branch)\"; }; f" ### inbound & outbound ###