Git Maintenance Guide

Git Cleanup

Here is how you can clean up a local repository by removing old branches, and so on.

git gc --force --prune=now

Clean up outdated non-existent references on the local machine:

git remote prune origin

Squash Git Commits Locally

git rebase -i HEAD~N

Where N is the last number of commits you want to squash.

You will then be presented with your text editor to squash commits. It goes from top-down so your oldest commit should be “pick”, and the others you can squash as needed.

To squash, replace pick with squash .

Then you can also edit the commit message in addition to pick.

Checkout Original File from One Branch to Current Branch

git checkout origin/[srcBranch] [filename]

This will checkout the file from some srcBranch . The filename is of course, denoted by filename.

Configure Git to Use lf as New Line Endings in Windows

To not use crlf as the line ending, but lf, you can do this:

git config --global core.autocrlf false
git config --global core.eol lf