git shenanigans

General notes

1. Mind that you can order your shell to set aliases and variables and execute commands automatically on every terminal startup by adding respective lines to your shell config file (e.g. .bashrc or .bash_profile in case of bash).

Aliases and commands can be simply noted verbatim in a config file.

Variables can be set with or without export builtin. This way your variable will be available only in a current shell:

YOUR_VARIABLE=value

And this way your variable will be available in a current shell and all processes started from it:

export YOUR_VARIABLE=value

2. Always remember to restrict access to your ssh private key files. In POSIX-compatible shells run this:

chmod 600 your_private_key_file_name

Handy aliases for commands

Stage all and commit

Set git alias:

git config --global alias.stacom '!git add . && git commit'

Set shell alias:

alias git_stacom="git add . && git commit"

Fancy log

Set git alias:

git config --global alias.history "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

Set shell alias:

alias git_history="git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

What it looks like:

What it looks like.

Authentication

Launch ssh-agent

Execute:

eval $(ssh-agent) > /dev/null 2>&1

Add key (identity) to ssh-agent

Set shell variable and alias:

GITSERVICES_SSH_PRIVATE_KEY="~/.ssh/your_private_key_file_name"

alias git_auth="ssh-add $GITSERVICES_SSH_PRIVATE_KEY"

Kill ssh-agent

Set shell alias:

alias kill_ssh_agent="pkill -f 'ssh-agent'"