Skip to content

Instantly share code, notes, and snippets.

@jaffarc
Forked from mislav/gh-rename-master
Created June 12, 2020 15:31
Show Gist options
  • Save jaffarc/afa7ababd13282a0c17360c10882ca9e to your computer and use it in GitHub Desktop.
Save jaffarc/afa7ababd13282a0c17360c10882ca9e to your computer and use it in GitHub Desktop.

Revisions

  1. @mislav mislav revised this gist Jun 12, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gh-rename-master
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ git remote set-head "$remote" "$newbranch"
    gh api -XPATCH "repos/:owner/:repo" -f default_branch="$newbranch" >/dev/null

    # update the base branch of all open pull requests
    for num in `gh pr list -B master -L999 | awk '{print $1}'`; do
    for num in `gh pr list -B master -L999 | cut -f1`; do
    gh api -XPATCH "repos/:owner/:repo/pulls/${num}" -f base="$newbranch" >/dev/null
    echo -n .
    done
  2. @mislav mislav revised this gist Jun 12, 2020. No changes.
  3. @mislav mislav revised this gist Jun 12, 2020. No changes.
  4. @mislav mislav created this gist Jun 12, 2020.
    26 changes: 26 additions & 0 deletions gh-rename-master
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/bin/bash
    # Usage: gh-rename-master <newbranch> [<remote>]
    #
    # Renames the "master" branch of the current repository both locally and on GitHub.
    #
    # dependencies: GitHub CLI v0.10
    set -e

    newbranch="${1?}"
    remote="${2:-origin}"

    git fetch "$remote" master
    git checkout -b "$newbranch" "${remote}/master" --no-track
    git push -u "$remote" "$newbranch"
    git remote set-head "$remote" "$newbranch"

    # update the default branch
    gh api -XPATCH "repos/:owner/:repo" -f default_branch="$newbranch" >/dev/null

    # update the base branch of all open pull requests
    for num in `gh pr list -B master -L999 | awk '{print $1}'`; do
    gh api -XPATCH "repos/:owner/:repo/pulls/${num}" -f base="$newbranch" >/dev/null
    echo -n .
    done

    printf '\nDone!\n'