How to configure Git aliases
Configuring Git aliases creates custom shortcuts for frequently used Git commands, significantly improving developer productivity and reducing typing overhead in daily workflows.
As the creator of CoreUI with 25 years of development experience since 2000, I’ve configured Git aliases in countless development environments to streamline version control operations and team collaboration.
The most effective approach involves creating aliases for common Git operations using the git config command with both simple shortcuts and complex multi-step operations.
This method provides personalized workflow optimization while maintaining consistency across different development environments and team members.
Use git config to create custom aliases for frequently used Git commands and complex operations.
# Simple command shortcuts
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
# Enhanced log commands with formatting
git config --global alias.lg "log --oneline --decorate --graph"
git config --global alias.last 'log -1 HEAD'
git config --global alias.visual '!gitk'
# Branch management aliases
git config --global alias.branches 'branch -a'
git config --global alias.remotes 'remote -v'
git config --global alias.aliases "config --get-regexp alias"
# Advanced workflow aliases
git config --global alias.pushup 'push --set-upstream origin HEAD'
git config --global alias.pushf 'push --force-with-lease'
git config --global alias.amend 'commit --amend --no-edit'
# Cleanup and maintenance
git config --global alias.cleanup "!git branch --merged | grep -v '\\*\\|main\\|master\\|develop' | xargs -n 1 git branch -d"
git config --global alias.prune-local "!git branch -vv | grep ': gone]' | awk '{print \$1}' | xargs git branch -d"
# Complex operations
git config --global alias.undo 'reset --soft HEAD~1'
git config --global alias.discard 'checkout -- .'
git config --global alias.unstash 'stash pop'
# View current aliases
git config --global --get-regexp alias
# Example usage after configuration:
# git co main # checkout main
# git lg # formatted log with graph
# git pushup # push and set upstream
# git cleanup # delete merged branches
Git aliases are stored in the global or local Git configuration and can range from simple command shortcuts to complex shell operations using the ! prefix for executing shell commands. The --global flag makes aliases available across all repositories, while omitting it creates repository-specific aliases. Aliases support parameter passing and can combine multiple Git commands, making them powerful tools for automating common workflows and reducing repetitive typing.
Best Practice Note:
This is the Git alias configuration we recommend for CoreUI development teams to maintain consistent, productive workflows. Start with simple aliases for frequently used commands and gradually add complex ones as your workflow patterns emerge, always documenting team-shared aliases for consistency.



