Yesterday I had to clean some very old branches on a project’s codebase. Here’s a few git tricks I had to use.

List merged branch (excluding master and staging) :

git branch --merged | egrep -v "(^\*|master|staging)"

Delete them locally :

git branch --merged | egrep -v "(^\*|master|staging)" | xargs -n 1 git branch -d

Delete them remotely :

git branch -r --merged | grep -v "origin/master$" | grep -v "origin/staging$" | sed 's/\s*origin\///' | xargs -n 1 git push --delete origin
git remote prune origin

Source : https://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-have-been-merged

Display branches with oldest commit datetime :

for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \\t$branch; done | sort -r

Source : https://www.digitalocean.com/community/tutorials/how-to-set-up-a-mail-relay-with-postfix-and-mailgun-on-ubuntu-16-04

TL;DR

sudo debconf-set-selections <<< "postfix postfix/main_mailer_type select Satellite system"
sudo debconf-set-selections <<< "postfix postfix/mailname string $HOSTNAME"
sudo debconf-set-selections <<< "postfix postfix/relayhost string smtp.mailgun.org"
sudo apt -y install postfix
sudo nano /etc/postfix/sasl_passwd

Ajouter la ligne suivante :

smtp.mailgun.org your_mailgun_smtp_user@your_subdomain_for_mailgun:your_mailgun_smtp_password
sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
sudo nano /etc/postfix/main.cf

En fin de fichier, ajouter :

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_sasl_mechanism_filter = AUTH LOGIN

Modifier également la ligne relayhost :

relayhost = smtp.mailgun.org
sudo systemctl restart postfix
sudo ufw status
php -r "mail('youremail@gmail.com', 'test', 'test');"

Pour terminer, on célèbre la victoire 🎉