Bash

How to set aliases in Git Bash for Windows

19 September 2026 · 9 min read

How to set aliases in Git Bash for Windows

Tired of typing the same Git commands over and over again in your Git Bash terminal on Windows? Do you find yourself frequently using lengthy commands like git commit -m “Your commit message” or git checkout -b feature/new-feature? Fortunately, there’s a solution to streamline your workflow and boost your productivity: setting aliases in Git Bash for Windows. An alias acts as a shortcut, allowing you to execute complex commands with just a few keystrokes. This not only saves you time but also reduces the chances of typos, making your Git experience smoother and more efficient. This guide will walk you through the process, step-by-step, empowering you to customize your Git Bash environment and become a more proficient developer. We’ll cover everything from locating your Git Bash profile to creating and managing your aliases.

Understanding Git Aliases and Their Benefits

Git aliases are essentially custom shortcuts for Git commands. They allow you to define shorter, more memorable commands that expand to execute longer, more complex Git instructions. Think of it as creating your own personalized Git language. For example, you can create an alias named co that expands to git checkout, or ci for git commit. This simple change can significantly reduce the amount of typing you do, especially when working with Git daily. Aliases can also be used to combine multiple Git commands into a single, easy-to-remember command.

The benefits of using Git aliases extend beyond just saving keystrokes. They improve consistency across your projects and among team members. By defining standard aliases, you ensure that everyone uses the same commands for common operations. This reduces the risk of errors and makes it easier to collaborate on projects. Furthermore, aliases can help you learn Git more effectively. By creating aliases for commands you use frequently, you reinforce your understanding of Git’s functionality. As stated in the Pro Git book, “Aliases can save you a lot of typing” [1]. And according to a Stack Overflow survey, developers who use command-line tools like Git are often more productive [2], implying that efficiency gains translate to overall productivity improvements. Using aliases is a small step that can have a big impact on your workflow.

Here’s a featured snippet-optimized paragraph: One of the most compelling reasons to set aliases in Git Bash for Windows is the sheer time saved. Instead of typing out lengthy commands repeatedly, aliases allow you to execute complex operations with just a few characters. This is particularly useful for frequently used commands, such as committing changes, checking out branches, or viewing logs. By streamlining your workflow, aliases free up your time to focus on more important tasks, such as writing code and solving problems.

Locating Your Git Bash Profile File

To create Git aliases in Git Bash on Windows, you need to find and edit your Git Bash profile file. This file is typically named .bashrc or .bash_profile and is located in your home directory. The home directory is usually C:\Users\[YourUsername]. However, sometimes it can be in C:\Users\[YourUsername]\Documents. If you’re having trouble finding it, open Git Bash and type cd ~ to navigate to your home directory. Then, type ls -a to list all files, including hidden ones. Look for .bashrc, .bash_profile, or .profile. If none of these files exist, you can create one.

If you find multiple profile files, it’s generally recommended to use .bashrc as it’s specifically designed for interactive shells like Git Bash. To edit the file, you can use a text editor like Notepad or Visual Studio Code. Right-click the file and select “Open with” to choose your preferred editor. If you’re comfortable with command-line editors, you can use vi or nano directly within Git Bash. Remember to save the file after making your changes. Ensuring you are editing the correct file is crucial; otherwise, your aliases won’t work as expected. In case of any errors or unintended changes, always keep a backup of your original profile file.

It’s important to note that changes to your profile file will only take effect after you restart Git Bash or source the file using the command source ~/.bashrc. This command tells Git Bash to reload the profile file and apply the new settings. By following these steps, you’ll be able to locate and edit your Git Bash profile file, setting the stage for creating your own custom Git aliases. Remember to double-check the file path and name to avoid any confusion.

Creating and Managing Git Aliases

Once you’ve located your Git Bash profile file, you can start creating aliases. Add aliases to the file using the following format: alias shortcut=‘git command’. For example, to create an alias for git commit -m, you would add the line alias cm=‘git commit -m’ to your profile file. Similarly, to create an alias for git checkout, you would add alias co=‘git checkout’. After adding your aliases, save the file and restart Git Bash or source the file using source ~/.bashrc to apply the changes.

Managing your Git aliases involves adding, modifying, and removing them as needed. To add a new alias, simply add a new line to your profile file following the format mentioned above. To modify an existing alias, find the line in your profile file and change the git command part. To remove an alias, delete the corresponding line from your profile file. Remember to save the file and restart Git Bash or source the file after making any changes. Regularly reviewing and updating your aliases ensures that they remain relevant and useful as your workflow evolves. Consider categorizing your aliases by function (e.g., commit-related, branch-related, log-related) to make them easier to manage.

Here are some example aliases that you might find useful:

  • alias st=‘git status’
  • alias br=‘git branch’
  • alias lg=‘git log –oneline –decorate –graph –all’

You can also create aliases with arguments. For example, alias cia=‘git commit -am’ will automatically stage all modified and deleted files before committing. Experiment with different aliases to find what works best for you. Remember to choose aliases that are easy to remember and type, but also descriptive enough to understand their function.

Advanced Alias Techniques and Tips

Beyond basic command shortcuts, Git aliases can be used to execute more complex operations. You can chain multiple Git commands together using && within an alias. For example, alias pusho=‘git push origin HEAD:refs/heads/origin/$(git branch –show-current)’ will push the current branch to the remote origin with one simple command. This is particularly useful for automating repetitive tasks or combining related operations.

Another advanced technique is using shell functions within aliases. This allows you to create aliases with conditional logic or dynamic behavior. To define a shell function, use the following syntax: alias alias_name=‘function_name () { commands; }’. Within the function, you can use shell scripting features like if statements, for loops, and variables. This opens up a wide range of possibilities for creating powerful and customized Git aliases. For instance, you could create an alias that automatically checks if there are any uncommitted changes before committing, preventing accidental commits of unfinished work.

Here are some tips for creating effective Git aliases:

  1. Choose aliases that are easy to remember and type.
  2. Use descriptive aliases that clearly indicate their function.
  3. Categorize your aliases by function to make them easier to manage.
  4. Regularly review and update your aliases to ensure they remain relevant.
  5. Don’t be afraid to experiment with different aliases and techniques.
Infographic here
FAQ: Setting Aliases in Git Bash --------------------------------
Q: Why aren't my aliases working after I added them to my .bashrc file?
A: Make sure you've saved the .bashrc file after adding the aliases. Also, you need to either restart Git Bash or source the file by running source ~/.bashrc for the changes to take effect.
Q: Can I use aliases to run commands other than Git commands?
A: Yes, you can use aliases to run any command that you would normally run in the Git Bash terminal. This includes commands like ls, cd, and mkdir.
Q: How do I remove an alias?
A: To remove an alias, simply delete the corresponding line from your .bashrc file and then restart Git Bash or source the file.
Q: Where is the .bashrc file located?
A: The .bashrc file is typically located in your home directory, which is usually C:\\Users\\\[YourUsername\].
By now, you should be well-equipped to start using Git aliases in your Git Bash environment on Windows. Embracing aliases can truly transform how you interact with Git, making your workflow faster, more efficient, and less prone to errors. The time you save and the frustration you avoid will quickly make this a worthwhile investment. Why not take a few minutes right now to create a couple of aliases for the Git commands you use most often? Experiment with different techniques, explore advanced features, and customize your Git Bash environment to perfectly suit your needs. Once you experience the power of aliases, you'll wonder how you ever managed without them. For further exploration, consider researching shell scripting to enhance your alias capabilities or exploring online Git communities for inspiration on useful alias configurations. Start small, experiment often, and watch your Git productivity soar! You can also refer to the official Git documentation [\[3\]](https://git-scm.com/docs) for more in-depth information. **Question & Answer :** How to alias commands in Git Bash for Windows downloaded from [git-scm](https://git-scm.com/)?

I mean Bash commands, not Git.

I’m on Windows 7.


Edit:

Writing aliases in .bashrc file (as suggested by @gturri) not adding it in console.(after system reboot)(I have never wrote alias for ls command so it should be some default alias.)

~/etc $ cat .bashrc alias ll='ls -l' alias dupa='ls -l' ~/etc $ dupa bash: dupa: command not found ~/etc $ ll total 0 ~/etc $ alias alias ll='ls -l' alias ls='ls -F --color=auto --show-control-chars' 

To configure bash aliases, it’s the same as if you were on a Unix platform: put them in a .bashrc in your home:

cd echo alias ll=\'ls -l\' >> .bashrc 

To have this change taken into account you should then either source this file (ie: run source .bashrc) or restart your terminal

(In some cases* you can find equivalent for .bashrc file in C:\Users\<username>\AppData\Local\GitHub\PortableGit_\etc\profile.d\aliases.sh. And you should add aliases in aliases.sh.)

(*this case is when you install Git for Windows GUI release from https://git-scm.com/download/win that contains GitBash)