Skip to content

Git: Clean up & disk

Git commands for clean up & disk (tags: #cleanup #disk #backup).

Index
3 items

Git: Discard all local changes

Destructive

Throws away uncommitted changes and untracked files. Unrecoverable for untracked files.

git reset --hard && git clean -fd
What each part does
  1. git reset --hardreset tracked files and the index to HEAD: uncommitted edits are gone
  2. &&continue only if the reset worked
  3. git clean -fddelete untracked files (-f) and directories (-d); ignored files stay unless you add -x

My note git clean -nd first to preview what would be deleted.

Also known as: reset hard · git clean · start over

Git: Delete local branches already merged

Caution

Removes local branches fully merged into main. -d refuses unmerged branches.

git branch --merged <main-branch> | grep -vE '^\*|<main-branch>' | xargs -r git branch -d
What each part does
  1. git branch --merged <main-branch>list local branches fully merged into main
  2. | grep -vE '^\*|<main-branch>'drop the current branch (marked *) and main itself
  3. | xargs -rpass the remaining names as arguments; -r: do nothing if the list is empty
  4. git branch -ddelete each branch; -d refuses unmerged ones

Also known as: prune branches · delete merged branches

Git: Prune deleted remote branches

Safe

Drop remote-tracking refs for branches deleted on the remote.

git fetch --prune
What each part does
  1. git fetchdownload new commits and refs from the remote
  2. --pruneremove origin/* refs for branches deleted on the remote

Also known as: fetch prune · stale branches

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…