From e15fc710541cae6ad0d912fcc8322e168800a3d3 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Mon, 17 Oct 2022 17:28:31 +0200 Subject: [PATCH] zsh,git: Add `git-make-fork` --- .config/git/config | 1 + .config/zsh/autoload/git/git-make-fork | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100755 .config/zsh/autoload/git/git-make-fork diff --git a/.config/git/config b/.config/git/config index 0d60b44..a29efe7 100644 --- a/.config/git/config +++ b/.config/git/config @@ -18,6 +18,7 @@ commit-last-msg = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-commit-last-msg\"" filter-repo = !git-filter-repo flog = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/glog\"" + make-fork = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-make-fork\"" ssync = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-ssync\"" submodule-rm = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-submodule-rm\"" track = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-track\"" diff --git a/.config/zsh/autoload/git/git-make-fork b/.config/zsh/autoload/git/git-make-fork new file mode 100755 index 0000000..62730d5 --- /dev/null +++ b/.config/zsh/autoload/git/git-make-fork @@ -0,0 +1,20 @@ +#!/usr/bin/env zsh + +emulate -L zsh -o err_return +local url branch + +# Make sure we're in a repo +git rev-parse + +git remote rename origin upstream + +# Assume that the fork is named equally +url="$(git remote get-url upstream)" +git remote add origin "git@github.com:druckdev/${url:t}" + +git fetch origin + +# Change remote tracking branch +if branch="$(git symbolic-ref HEAD 2>/dev/null)"; then + git branch -u origin/"${branch#refs/heads/}" +fi