TIL

Today I Learned. 知ったこと、学んだことを書いていく

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

git push origin :{remote branch name}

これでリモートブランチを削除できる



例)developというリモートブランチを削除する

$ git branch -a
  develop
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/master
$ git push origin :develop
$ git branch -a
  develop
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

GitHubで消えていることが確認できた。追跡ブランチも消えてくれるのいいね


2017/10/04 追記

git push origin :{remote branch name}では追跡ブランチは削除されていなかった!!

git branch -vvで確認したところ、追跡ブランチは存在していた

git push origin :develop 実行前

$ git branch -vv
* develop 6a0da68 [origin/develop] update hello.txt
  master  8b1dd7d [origin/master] add hello.txt

developはorigin/developを追跡していることがわかる


git push origin :develop 実行後

$ git branch -vv
* develop 6a0da68 [origin/develop: gone] update hello.txt
  master  8b1dd7d [origin/master] add hello.txt

ん??origin/develop: goneって何!!!developリモートブランチがないよ!ってことかな?存在しないリモートブランチを追跡しようとしているため、このような表示になっているのかも


developブランチがorigin/developを追跡しないようにする

git branch --unset-upstreamを実行すれば追跡をやめることができる

$ git branch --unset-upstream
$ git branch -vv
* develop 6a0da68 update hello.txt
  master  8b1dd7d [origin/master] add hello.txt

origin/develop: goneがでなくなった!!!




参考文献

Git で不要になったリモートブランチを削除する - koogawa log