⑨ lab ≡ ByteLabs

Git/Refetch Branch

Alas, my local branch is broken beyond repair. Any hope of a simple resolution is shattered after scrutinizing the amount of conflicts. This is the moment when you realise Git is ugly too

In a large project with many developers and branches it is inevitable to occasionally run into the situation where you break your local checkout of a remote branch beyond repair. After trying out in vain mysterious git incantations scraped off of random stackoverflow forum entries, one can’t help but fall into despair thinking “why it is so difficult to just refetch the origin branch replacing the local broken one”.

There is no single command to perform this task. A combination of steps is required. First the broken local branch B is deleted, next a re-fetch from its origin is required, followed by a checkout:

% git branch -D B
% git fetch origin B
% git checkout -b B origin/B