Git alias

Git alias

Git Alias: Create Shortcuts for Git Commands

Git aliases allow you to create shortcuts for frequently used Git commands, making your workflow faster and more efficient.

1. Creating a Git Alias

To create an alias, use:

git config --global alias.<shortcut> "<command>"

For example:

git config --global alias.st "status"

Now, you can run git st instead of git status.

2. Useful Git Alias Examples

๐Ÿ”น Shorten Common Commands

git config --global alias.co "checkout" git config --global alias.br "branch" git config --global alias.cm "commit -m" git config --global alias.df "diff" git config --global alias.lg "log --oneline --graph --all --decorate"

๐Ÿ“Œ These aliases allow you to run commands like:

  • git co main → Instead of git checkout main
  • git br → Instead of git branch
  • git cm "Initial commit" → Instead of git commit -m "Initial commit"

๐Ÿ”น Create a Better git log View

git config --global alias.lg "log --oneline --graph --decorate --all"

๐Ÿ“Œ Now, running git lg will display a visual history of commits.

๐Ÿ”น Undo Last Commit (But Keep Changes)

git config --global alias.uncommit "reset --soft HEAD~1"

๐Ÿ“Œ Running git uncommit undoes the last commit but keeps your changes.

๐Ÿ”น Clean Untracked Files

git config --global alias.cleanall "clean -df"

๐Ÿ“Œ git cleanall removes untracked files and directories.

3. Listing All Aliases

To see all configured aliases, run:

git config --global --list | grep alias

4. Removing an Alias

If you want to remove an alias:

git config --global --unset alias.<shortcut>

For example, to remove git co:

git config --global --unset alias.co

๐Ÿ”น Conclusion

Git aliases save time and reduce typing. Setting up custom aliases allows you to speed up your workflow and work more efficiently.

Do you want help setting up a specific alias? Let me know! ๐Ÿš€

Soeng Souy

Soeng Souy

Website that learns and reads, PHP, Framework Laravel, How to and download Admin template sample source code free.

Post a Comment

CAN FEEDBACK
close