DEV Community

Cover image for How to Install and Configure Git with Aliases in Ubuntu 22
Francisco Moretti
Francisco Moretti

Posted on • Originally published at franciscomoretti.com

How to Install and Configure Git with Aliases in Ubuntu 22

This guide will guide you through the process of installing and configuring Git with aliases in Ubuntu 22.04. Git is an essential tool for version control, and aliases can greatly enhance your workflow by providing shorthand commands for common Git operations. Let's get started! πŸ˜„

Step 1: Installing Git

Let's install Git on your Ubuntu 22.04 system. Open your terminal and follow these steps:

  1. Update your package list by running the command:
sudo apt update
Enter fullscreen mode Exit fullscreen mode
  1. Install Git using the following command:
sudo apt install git
Enter fullscreen mode Exit fullscreen mode

Awesome! Now that you have Git installed, let's move on to configuring some helpful aliases.

Step 2: Configuring Git Aliases

Aliases allow us to create shortcuts for frequently used Git commands, making our workflow smoother and more efficient. To configure aliases, open your terminal and follow these steps:

  1. Set up some basic aliases recommended by the Git documentation by executing these commands:
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.last 'log -1 HEAD'
Enter fullscreen mode Exit fullscreen mode

These aliases will be useful when you need to perform common operations such as checking out branches, creating branches, committing changes, checking the status, and viewing the last commit.

  1. Additionally, here's a personal favorite alias that I find incredibly useful. It deletes all local branches that have already been merged into the currently checked out branch.

Add this to your Git configuration by running git config -e --global

[alias]
    cleanup = "!git branch --merged | grep  -v '\\*\\|master\\|develop' | xargs -n 1 -r git branch -d"
Enter fullscreen mode Exit fullscreen mode

This alias helps keep your local branches clean and tidy, especially when you've been working on a project for a while and have accumulated multiple branches.

With these aliases set up, you're on your way to becoming a Git power user! πŸŽ‰

Step 3: Setting Up Git with GitHub

If you're not already using GitHub, I highly recommend it. GitHub is the most used platform for collaboration and code hosting. To set up Git with GitHub, follow the official GitHub documentation: Set Up Git with GitHub.

By integrating Git with GitHub, you'll get access to a ton of features for your modern web development projects.

Conclusion

Congrats on installing and configuring Git with aliases in Ubuntu 22.04! πŸŽ‰ With aliases you can type less and improve your productivity as a web developer. Remember to refer to this guide for future installations and configurations. Happy coding! ✨

Top comments (0)