LoginSignup
4
0

More than 5 years have passed since last update.

1コマンドでまとめて複数のプルリクをmergeする方法

Last updated at Posted at 2018-12-11

1コマンドでまとめて複数のプルリク(pr)をmergeする方法

Terminal

% git fetch upstream
% git checkout -b new_stgup_branch upstream/master
% toMergeForStgUp

コンフリクトでこけたら、 直して、また toMergeForStgUp を叩けば続きだけmergeできる

事前準備

hub コマンドinstall
https://github.com/github/hub

.git/config

[remote "upstream"]
    url = git@github.com:<オーナー名/リポジトリ名>.git
    fetch = +refs/heads/*:refs/remotes/upstream/*
    fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*

.zshrc

## まとめてstgにあげるprをmerge
# githubのラベルが s-uptoStaging または s-Staging がついているものをまとめてmerge
# \d{5} の数字は pr番号の桁数
# 適宜、チームのルールに合わせて変える

function toMergeForStgUp(){
  hub pr list -f "%i %l%n" | grep -e s-uptoStaging -e s-Staging | grep -o -E "\d{5} " | while read i
  do
    git merge upstream/pr/$i
  done
}

-f "%i %l%n" で、 pr id と ラベル情報を改行で取得。タイトルにissue番号が入っている時に grep -o -E "\d{5} " で該当にならないように 必要な情報にしぼる。

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0