LoginSignup
13
10

More than 5 years have passed since last update.

Githubでリモートブランチを削除しないようにする

Posted at
  • Githubでdevelop -> masterへのマージをPullRequestでやろうとして、マージ後にうっかり削除してしまった場合があるので、その防止
    • PullRequestマージ後にブランチ削除ボタン(Delete branch)が出るので、featureブランチを削除するときと同じクセでつい消してしまうことがある 20151130_082312.jpg
      • 消しても、「Restore branch」ボタンがあるのですぐ戻せるけど。。。

手順(例:developを削除しないようにする)

1 リポジトリの「Settings」を選択
2 「Branches」を選択し、「Protected branches」の「Choose a branch」コンボボックスから、削除させたくないブランチ(ここではdevelop)を選択
20151130_083352.jpg
3 「Protected this branch」にチェックを入れて、「Save changes」ボタンを押下する
20151130_082341.jpg
4 「Protected branches」にdevelopブランチが入った
20151130_082351.jpg
5 この状態でPullRequestして、develop -> masterへのマージをすると、マージ後にブランチ削除のボタンが出ない
20151130_082302.jpg

  • ちなみにgitコマンドでも削除できない
git push --delete origin develop

remote: error: GH006: Protected branch update failed for refs/heads/develop.
remote: error: Cannot delete a protected branch
To git@github.com:xxx/hoge.git
 ! [remote rejected] develop (protected branch hook declined)
error: failed to push some refs to 'git@github.com:xxx/hoge.git'
13
10
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
13
10