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!
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.
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.
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 .
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With