Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My Git bash forgets my aliases. What can I do?

Tags:

git

bash

I am working with the latest Git bash for Windows, on my laptop running Windows 7. When I define my aliases like:

$ alias gitc='git commit -a' 

Everything works well during the session, but I cannot recover them if I close and open the bash. The command history is preserved, though.

What should I do? What I have missed?

Thanks!

like image 611
Antoine Lizée Avatar asked Dec 05 '12 02:12

Antoine Lizée


People also ask

Where are git bash aliases stored?

A global alias is stored in the global . gitconfig file which is available under the user home directory in Linux, for a local alias it is inside the . git folder within the repository, or you can say “/. git/config” is the relative path for the file.

Where is bash aliases file?

Aliases allow you to define new commands by substituting a string for the first token of a simple command. They are typically placed in the ~/. bashrc (bash) or ~/. tcshrc (tcsh) startup files so that they are available to interactive subshells.

Where do git aliases live?

Git aliases can be stored globally or in individual repositories. Unless you have a very specific reason to keep an alias scoped to a project, I would recommend editing the global config file, which is located at ~/. gitconfig .


2 Answers

When you open the git bash type in the command touch .bash_profile. Following this type vim .bash_profile. You can then add your aliases to this file. Save the file and reopen the git bash and your aliases should work as expected.

This method allows you to create aliases for any bash command available in git bash however as others have answered it is also possible to create git specific aliases using git itself.

like image 157
ctor Avatar answered Sep 24 '22 19:09

ctor


Instead of modifying your bash_profile you can setup a .gitconfig and add aliases like this:

[alias]   st = status   ci = commit   br = branch   co = checkout   df = diff   lg = log -p 
like image 44
AJ. Avatar answered Sep 20 '22 19:09

AJ.