ハイパーニートプログラマーへの道

頑張ったり頑張らなかったり

リモートで削除されたブランチがローカルに残ってしまう問題を解消する。git remote prune

$ git branch -aしてみると、なんかリモートへの参照に余計なのが残っちゃてるよ。

$ git branch -a                                                                                
  account-activation-password-reset                                                                                                                                
  following-users                                                                                                                                                  
  log-in-log-out                                                                                                                                                   
  master                                                                                                                                                           
  modeling-users                                                                                                                                                   
  sign-up                                                                                                                                                          
  updating-users                                                                                                                                                   
  user-microposts                                                                                                                                                  
* using-rspec                                                                                                                                                      
  remotes/heroku/master                                                                                                                                            
  remotes/origin/master                                                                                                                                            
  remotes/origin/static-pages                                                                                                                                      
  remotes/origin/static-pages-execises    
  remotes/origin/static-pages                                                                                                                                      
  remotes/origin/static-pages-execises    

この2つはBitbucket上で消したのですけど、それが反映されてないのかなあ?

ローカルからは削除しているので
$ git push remote <branch name>してみたけどダメ。そりゃそうか。

$ git push origin :static-pages                                                                
error: unable to delete 'static-pages': remote ref does not exist                                                                                                  
error: failed to push some refs to 'git@bitbucket.org:noriyotcp/sample_app.git'

ないんなら削除できないですよね。デスヨネー

git remote pruneを使用する

Git - リモートで消されたブランチが手元で残ってしまう件を解消する - Qiita

git - How to delete "remote" branch that still shows locally? - Stack Overflow

--dry-runオプションで実行前に確認できる。

$ git remote prune --dry-run origin                                                            
Pruning origin                                                                                                                                                     
URL: git@bitbucket.org:noriyotcp/sample_app.git                                                                                                                    
 * [would prune] origin/static-pages                                                                                                                               
 * [would prune] origin/static-pages-execises   
$ git remote prune origin                                                                      
Pruning origin                                                                                                                                                     
URL: git@bitbucket.org:noriyotcp/sample_app.git                                                                                                                    
 * [pruned] origin/static-pages                                                                                                                                    
 * [pruned] origin/static-pages-execises
$ git branch -a                                                                                
  account-activation-password-reset                                                                                                                                
  following-users                                                                                                                                                  
  log-in-log-out                                                                                                                                                   
  master                                                                                                                                                           
  modeling-users                                                                                                                                                   
  sign-up                                                                                                                                                          
  updating-users                                                                                                                                                   
  user-microposts                                                                                                                                                  
* using-rspec                                                                                                                                                      
  remotes/heroku/master                                                                                                                                            
  remotes/origin/master

消えてるー。にしてもローカルブランチ多すぎじゃ・・・。


まだremoteにも残っているのであれば、ローカルで削除>リモートへプッシュ、という流れでいいみたいですな。

git branch -d <branch name>
git push origin :<branch name> 

tomoのconcrete5 :: Bitbucketでbranchを使ってみた(メモ)