DRYな備忘録

Don't Repeat Yourself.

git fetchできない【git】

問題

git fetchしようとすると以下のように叱られる

[12:15:56] ✔  git fetch origin 
error: unable to resolve reference refs/remotes/origin/wip/i: Not a directory
From github.com:otiai10/kanColleWidget
 ! [new branch]      wip/i      -> origin/wip/i  (unable to update local ref)
error: unable to resolve reference refs/remotes/origin/wip/loader: Not a directory
 ! [new branch]      wip/loader -> origin/wip/loader  (unable to update local ref)
error: unable to resolve reference refs/remotes/origin/wip/mainte: Not a directory
 ! [new branch]      wip/mainte -> origin/wip/mainte  (unable to update local ref)
error: unable to resolve reference refs/remotes/origin/wip/t: Not a directory
 ! [new branch]      wip/t      -> origin/wip/t  (unable to update local ref)
 * [new tag]         v0.6.0.2   -> v0.6.0.2
 * [new tag]         v0.6.0.4   -> v0.6.0.4
error: some local refs could not be updated; try running
 'git remote prune origin' to remove any old, conflicting branches
[12:16:06]

原因

error: unable to resolve reference refs/remotes/origin/wip/i: Not a directory

wipっていうブランチが追跡ブランチに残ってて、それがリモートにあるwip/tとかwip/iとかのブランチ名と名前衝突してる。 具体的には、wipってブランチとして作業してたんだけど、別環境で作業進めるうえで、wip/hogeっていうブランチの切り方したくなって、それ以降リモートのwipはブランチ名ではなくブランチディレクトリ名として扱われていたのde R。

解決

# ローカルブランチ消す
[12:15:51] ✔  git branch -d wip 
error: The branch 'wip' is not fully merged.
If you are sure you want to delete it, run 'git branch -D wip'.
[12:15:53] ✔  git branch -D wip
Deleted branch wip (was 8b581eb).

# 追跡ブランチも消す
[12:16:15] ✔  git branch -d -r origin/wip
Deleted remote branch origin/wip (was 8b581eb).

うーん

ローカルと追跡と両方、同時に消す方法無いのか?

[12:28:25] ✔  git branch
* develop
  master
[12:28:28] ✔  git brnch -r
git: 'brnch' is not a git command. See 'git --help'.

Did you mean this?
    branch
[12:28:36] ✔  git branch -r
  origin/HEAD -> origin/develop
  origin/develop
  origin/feature/fix-bug
  origin/feature/log-server
  origin/feature/modify-sound-ui
  origin/feature/notification-offset-setting
  origin/gh-pages
  origin/gh-pages-grat
  origin/master
  origin/wip/i
  origin/wip/loader
  origin/wip/mainte
  origin/wip/t
[12:28:41] ✔  git chekout -t origin/wip/loader
git: 'chekout' is not a git command. See 'git --help'.

Did you mean this?
    checkout
[12:28:56] ✔  git checkout -t origin/wip/loader
Branch wip/loader set up to track remote branch wip/loader from origin.
Switched to a new branch 'wip/loader'
[12:29:09] ✔  git branch
  develop
  master
* wip/loader
[12:29:13] ✔  git checkout develop
Switched to branch 'develop'
Your branch and 'origin/develop' have diverged,
and have 4 and 44 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)
[12:29:22] ✔  git branch -d -r origin/wip/loader
Deleted remote branch origin/wip/loader (was c8d0f4a).
[12:29:40] ✔  git branch
* develop
  master
  wip/loader
[12:29:45]

ちなみに

git remote rmでリモート登録を削除すると、対応する追跡ブランチもgit branch -d -rした時と同じように消してくれた

DRYな備忘録