Git Squash (All)

How to squash all your commits from a feature branch before merging.

--

Photo by Karina Vorozheeva on Unsplash

Taking the code from steve crozz, I converted this into a function to run in my shell. This creates a new branch and collapses all your commits into a one.

freebase() {
TOPIC=$(git branch | grep '*' | cut -d ' ' -f2)
NEWBASE="${1:-main}"
PREVSHA1=$(git rev-parse HEAD)

echo "Freebasing…

--

--

Daniel Ellis Research

Research Software Engineer specialising in High-Performance Computing and Data Visualisation. — PhD in Atmospheric Chemistry and Masters in Theoretical Physics.