【问题标题】:Is it possible to create pull request in github from terminal, not from website是否可以从终端而不是网站在 github 中创建拉取请求
【发布时间】:2018-04-15 08:46:36
【问题描述】:

我想直接从终端创建拉取请求

我只想做一些命令,比如:

git pull-create-pull-request localBranch git@github.com:user/repo originBranch

【问题讨论】:

    标签: git terminal pull-request


    【解决方案1】:

    看看github的hub命令。如果您按照文档说明安装它,则可以通过运行以下命令打开拉取请求:

    git pull-request
    

    【讨论】:

    • 默认情况下,此命令会创建对 master 的拉取请求,但我想创建对自定义的请求。例如,我在本地有test 分支,它被推送到原点。现在我想向dev 分支创建拉取请求
    • 我找到了! hub pull-request -m 'message to pull request' -o -b dev -o --- 将在 PR 的浏览器页面中打开 -b dev --- 从本地分支拉取请求到 orgin/dev
    【解决方案2】:

    基于 Paul Irish 的 git open script,我创建了一个 git create-pr 脚本,该脚本可以从当前签出的分支创建 GitHub PR。

    请注意,这对我的工作流程很有效,一些队友已经使用过它,但它可能包含错误。

    #!/usr/bin/env bash
    
    # Opens the "Open Pull Request" GitHub page for a repo/branch in your browser.
    # based on git-open by Paul Irish (https://github.com/paulirish/git-open/)
    #
    # git create-pr
    # git create-pr [remote] [branch]
    
    # are we in a git repo?
    git rev-parse --is-inside-work-tree &>/dev/null
    
    if [[ $? != 0 ]]; then
      echo "Not a git repository." 1>&2
      exit 1
    fi
    
    
    # assume origin if not provided
    # fallback to upstream if neither is present.
    remote="origin"
    if [ -n "$1" ]; then
      if [ "$1" == "issue" ]; then
        currentBranch=$(git symbolic-ref -q --short HEAD)
        regex='^issue'
        if [[ $currentBranch =~ $regex ]]; then
          issue=${currentBranch#*#}
        else
          echo "'git open issue' expect branch naming to be issues/#123" 1>&2
          exit 1
        fi
      else
        remote="$1"
      fi
    fi
    
    remote_url="remote.${remote}.url"
    
    giturl=$(git config --get "$remote_url")
    if [ -z "$giturl" ]; then
      echo "$remote_url not set." 1>&2
      exit 1
    fi
    
    # get current branch
    if [ -z "$2" ]; then
      branch=$(git symbolic-ref -q --short HEAD)
    else
      branch="$2"
    fi
    
    # Make # and % characters url friendly
    #   github.com/paulirish/git-open/pull/24
    branch=${branch//%/%25} && branch=${branch//#/%23}
    
    # URL normalization
    # GitHub
    giturl=${giturl/git\@github\.com\:/https://github.com/}
    
    # handle SSH protocol (links like ssh://git@github.com/user/repo)
    giturl=${giturl/#ssh\:\/\/git\@github\.com\//https://github.com/}
    
    providerUrlDifference=compare
    
    giturl=${giturl%\.git}
    
    giturl="${giturl}/${providerUrlDifference}/${branch}?expand=1"
    
    # get current open browser command
    case $( uname -s ) in
      Darwin)  open=open;;
      MINGW*)  open=start;;
      CYGWIN*) open=cygstart;;
      MSYS*)   open="powershell.exe –NoProfile Start";;
      *)       open=${BROWSER:-xdg-open};;
    esac
    
    # open it in a browser
    $open "$giturl" &> /dev/null
    exit $?
    

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 1970-01-01
      • 2014-12-24
      • 2020-03-22
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-17
      相关资源
      最近更新 更多