Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Git aliases script

This script sets up your Git environment by creating/setting several common aliases and shortcuts for them.

# Remove all existing aliases
current_aliases=$(git config --get-regexp alias);
if [ ${#current_aliases} -gt 0 ]; then
echo 'Removing all existing aliases';
git config --global --remove-section alias;
# Add aliases
echo 'Creating custom aliases';
git config --global alias.sync !'git pull && git push';
git config --global !'git config --get-regexp alias';
git config --global alias.pretty-log !'git log --pretty=format:"%ad%C(red)%d %C(yellow)[%h] %C(green)%cn: %Creset%s " --decorate --date=short';
git config --global alias.trash !'git checkout . && git reset --hard HEAD && git clean -fd';
git config --global alias.changed-files !'git show --pretty="" --name-only';
git config --global !'git show -s $1 && echo "----------------------------------------" && git changed-files $1';
git config --global alias.changed-files-diff !'git difftool $1^ $1';
git config --global alias.list-untracked-files !'git ls-files --others --exclude-standard';
git config --global alias.delete-untracked-files !'git list-untracked-files | xargs -n 1 rm -fr';
git config --global alias.list-staged-files !'git diff --cached --name-only';
git config --global alias.list-unstaged-files !'git diff --name-only';
git config --global alias.unlock !'rm ./.git/index.lock';
git config --global alias.nuke !'git trash && git clean -fxd';
git config --global alias.delete-other-branches !'git branch | grep -v "\*" | xargs -I {} git br -D {}';
git config --global alias.all = !'f() { ls | xargs -I{} git -C {} $1; }; f'
# Add shortcuts
echo 'Creating shortcut aliases';
git config --global !'git checkout';
git config --global !'git status';
git config --global !'git branch';
git config --global !'git show-aliases';
git config --global !'git pretty-log';
git config --global alias.cp !'git cherry-pick';
git config --global !'git trash';
git config --global !'git changed-files';
git config --global !'git show-summary';
git config --global !'git changed-files-diff';
git config --global alias.luf !'git list-untracked-files';
git config --global alias.duf !'git delete-untracked-files';
git config --global alias.lsf !'git list-staged-files';
git config --global alias.lusf !'git list-unstaged-files';
git config --global alias.dob !'git delete-other-branches';
# Add typo correction
echo 'Creating typo aliases';
git config --global alias.commti 'commit';
git config --global alias.sttaus 'status';
git config --global alias.reste 'reset';
echo 'Done';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.