0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Git】コマンドラインベースでブランチを削除する最も簡単な方法

Last updated at Posted at 2019-11-08

Gitでブランチを削除する方法です。
ローカルブランチ、リモートブランチそれぞれについて書きました。
いろいろな方法がありますが、最も簡単と思われるものをチョイスしています。

対象ツール・環境

  • Git
  • OS:Windows10
  • コマンドプロンプト
  • リモートリポジトリ:CodeCommit

手順

1. ローカルブランチを削除する

(1)削除するブランチが作業中の場合は別のブランチに切り替える

> git checkout 別のブランチ(名)

(2)以下のコマンドを実行し、対象ブランチを削除

> git branch -D 削除するブランチ名

【例】ローカルのdummy1ブランチ(作業中)を削除する場合

> git checkout master     ## masterブランチに切り替え
> git branch -D dummy1    ## dummy1ブランチを削除

2. リモートブランチを削除する

(1)以下のコマンドを実行し、対象ブランチを削除

> git push origin :削除するブランチ名

【例】リモートのdummy2ブランチを削除する場合

> git push origin :dummy2

※補足事項

  • 対象ブランチをfetchしていなくても削除可能
  • ローカルで対象ブランチ由来のブランチで作業中でも削除可能

でした。

参考

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?