I've collated some git commands which are an essential part of my workflow (interactive rebasing - where would I be without you 😋). Hopefully you'll find some nuggets of wisdom below.

As they are verbose, I've aliased them to save those precious seconds of typing. For aliasing, I use my .gitconfig file rather than aliasing in my .bashrc file. I prefer keeping my .bashrc file clutter free and I figured if Git gives me a place to put aliases, I should put them there 🤷🏻‍♂️.

Git has a quick and easy way of adding aliases to your .gitconfig. Let's alias checkout to co.

git config --global alias.co checkout

The alias is added to your .gitconfig file.

    co = checkout

Git aliases

Want to quickly stage all your modified files

git ls-files | xargs git add

Want to use your re-use last commit message when commiting staged changes

git commit -C HEAD@{1}

Want to edit the message of the last commit and squash both staged/unstaged changes into the same commit

git commit -a --amend

Want to interactively rebase your current branch only up to where it diverges with the remote master branch

git rebase -i HEAD~$(git rev-list --count origin/master..HEAD)

Want to time stamp your stashes

git stash save "$(date)"

Want to make sure you're not overwriting commits on the remote branch that you haven't pulled to your local branch when pushing?

git push --force-with-lease

Want to rebase off remote master?

git pull --rebase origin master

Want to get rid of all uncommitted changes

git checkout -- .

Last but not least - want to view all your aliases?

git config -l | grep alias | cut -c 7-


Remembering aliases is hard. Luckily there's a plugin for remembering forgotten aliases! If the Git command you're executing has an alias, the plugin will kindly remind you of this alias by printing it to the command line. The plugin also works with shell aliases.