33.11 Git Cleanup

20210923

If things get confusing or go wrong, some salient advice from xkcd: delete the project, and download a fresh copy.

It does not always need to be that drastic. Things can go wrong when trying to merge upstream changes into your own local working copy before you then want to submit your changes either directly or through a pull request (the latter is recommended).

Git is pretty good at suggesting what to do at different stages of the workflow, so follow those suggestions.

Here’s a few commands to try to get things back into sync when things seem to have gone wrong.

A local repository may retain known branches over time even though they get deleted from the remote repository.

To delete stale references from the local copy:

git remote prune origin

To then fetch updates (i.e. re-sync with origin) and prune:

git fetch --prune origin

You can delete (-d) a branch locally. If it exists upstream it can still be retrieved with a checkout.

git branch -d kayon/validator

To prune all local branches that have been deleted from upstream, thanks Theo Darmawan and Stack Overflow:

git fetch -p
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d


Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0