On a bench update this git ‘reference broken’ issue bit me, for some reason:
frappe@ubuntu1804lts:~/frappe-bench$ bench update
INFO:bench.utils:Updating bench
INFO:bench.utils:git pull
Already up to date.
INFO:bench.utils:Bench Updated!
INFO:bench.utils:./env/bin/pip install Pillow
Requirement already satisfied: Pillow in ./env/lib/python3.6/site-packages (7.0.0)
Backing up sites...
INFO:bench.app:pulling frappe
INFO:bench.utils:git pull upstream version-12
From https://github.com/frappe/frappe
* branch version-12 -> FETCH_HEAD
Already up to date.
INFO:bench.utils:find . -name "*.pyc" -delete
INFO:bench.app:pulling erpnext
INFO:bench.utils:git pull upstream version-12
From https://github.com/frappe/erpnext
* branch version-12 -> FETCH_HEAD
error: cannot lock ref 'refs/remotes/upstream/version-12': unable to resolve reference 'refs/remotes/upstream/version-12': reference broken
! [new branch] version-12 -> upstream/version-12 (unable to update local ref)
Traceback (most recent call last):
File "/usr/local/bin/bench", line 11, in <module>
load_entry_point('bench', 'console_scripts', 'bench')()
File "/home/frappe/.bench/bench/cli.py", line 40, in cli
bench_command()
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/frappe/.bench/bench/commands/update.py", line 68, in update
_update(pull, patch, build, bench, auto, restart_supervisor, restart_systemd, requirements, no_backup, force=force, reset=reset)
File "/home/frappe/.bench/bench/commands/update.py", line 88, in _update
pull_all_apps(bench_path=bench_path, reset=reset)
File "/home/frappe/.bench/bench/app.py", line 249, in pull_all_apps
remote=remote, branch=get_current_branch(app, bench_path=bench_path)), cwd=app_dir)
File "/home/frappe/.bench/bench/utils.py", line 185, in exec_cmd
raise CommandFailedError(cmd)
bench.utils.CommandFailedError: git pull upstream version-12
frappe@ubuntu1804lts:~/frappe-bench/apps/erpnext$ git status
On branch version-12
Your branch is based on 'upstream/version-12', but the upstream is gone.
(use "git branch --unset-upstream" to fixup)
git branch --unset-upstream
did not fix the problem…
frappe@ubuntu1804lts:~/frappe-bench/apps/erpnext$ git fetch upstream
remote: Enumerating objects: 18213, done.
remote: Counting objects: 100% (12157/12157), done.
remote: Compressing objects: 100% (4594/4594), done.
remote: Total 10856 (delta 8498), reused 8447 (delta 6253), pack-reused 0
Receiving objects: 100% (10856/10856), 2.05 MiB | 3.48 MiB/s, done.
Resolving deltas: 100% (8498/8498), completed with 829 local objects.
error: cannot lock ref 'refs/remotes/upstream/version-12': unable to resolve reference 'refs/remotes/upstream/version-12': reference broken
From https://github.com/frappe/erpnext
! [new branch] version-12 -> upstream/version-12 (unable to update local ref)
However this pointer did help: git pull fails "unable to resolve reference" "unable to update local ref" - Stack Overflow
It seems the bad ref was my version-12 reference, as this fixed the problem:
frappe@ubuntu1804lts:~/frappe-bench/apps/erpnext$ rm .git/refs/remotes/upstream/version-12
frappe@ubuntu1804lts:~/frappe-bench/apps/erpnext$ git fetch
hope this helps