THE Git Toolbelt
Tips & Tricks to make your daily work much easier.

I still remember those days using visual SVN clients to version my source code, when you didn’t need to remember any command line or --arguments, but things had changed and software nowadays gets bigger and complex and we find our ways to be up to date with the best practices and tools.
As developers we have to deal with merging conflicts, branch rebases, releases and tags, comparing and reverting changes
In my daily routing as a software developer I have to merge conflicts, rebase branches , compare and revert changes, create tags and releases and also do code reviews. Most of the time we are repeating over and over again the same git commands, so…
please DRY! DRY!
Git Aliases
Aliases are really simple to use you just need to add the correspondent name and the commands you want to execute and there are two ways create them:
The first one (recommended) is adding a line in the [alias] section of your .gitconfig
Simple Logs
ls = log --oneline
Another way is to use the git config --global command, it will save the alias directly in your .gitconfig.
git config --global alias.ls 'log --oneline'and then type git ls

Prettify and Customize your logs
lds = !git log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=shortand then type git lds

Graph your branch Structure
The --graph option draws an ASCII graph representing the branch structure of the commit history. This is commonly used in conjunction with the --oneline and --decorate commands to make it easier to see which commit belongs to which branch:
lgs = !git log --all --decorate --oneline --graph
Amend it easy
amend = commit --amend -mSquash all on a previous commit
“Squash” all uncommitted and un-staged changes in your branch and add them to your previous commit, amending it before pushing the changes. Instead of commit and then rebase and squash.
caa = commit -a --amend -C HEADUndo previous commit
undo-commit = reset --soft HEAD~1Multiple Git commands & Bash 💪😄 (|, grep & more)
We can get more from the aliases if you use them along with any Bash command such us pipes and grep and also others git commands
use 👉 ! 👈 at the beginning
If the alias expansion is prefixed with an exclamation point, it will be treated as a shell command.
Remove all the branches already merged in master
dmerged = !git branch --merged | grep -v \"\\*\" | xargs -n 1 git branch -dGit Alises limitations
All above aliases are simple to craft and use, BUT after working with them for a bit you’ll realise that the are some limitation with the simple aliases cannot have parameters. really ? 🤔 no worries there is a way 😜
yourAlias = "!f() { 〈your complex command〉 }; f"Jump to [branch]
I do this all the time, jumping from master to my working branches.
and then type git jump [branch]
jump = "!f() { git checkout $1; git pull; }; f"the above is an example from @durdn
Rename [branch] to done-[branch]
In some of my workflows I wanted to quickly rename branches prepending done- to their names. Here is the alias that came out of that workflow:
done = "!f() { git branch | grep "$1" | cut -c 3- | grep -v done | xargs -I{} git branch -m {} done-{}; }; f"last but not least a list of commands that could be useful for you
credits:
