Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create alias Git Bash Windows 10

Tags:

git

bash

How to create alias for Git Bash on Windows 10? I need to create an alias of the long path to my project folder so I don't have to type it again and again whenever I open bash. I've searched for answers and tried several "correct answers" but none has worked for me so far.

They include: create a .bashrc or some people suggest .bashrc. (after creating this file, I cannot do anything with it. windows says

Could not find this item This is no longer located in C:\. Verify the item's location and try again.

) echo alias='<path>' > .bashrc (iI've also tried >>)

I can edit the file .bashrc and put aliases in there but none of them works. I've tried editing the .gitconfig file in my home folder [alias] =''

Same result whenever I type: cd <alias name>:

No such file or directory

All I need to do is to type: cd and it will lead me to ~///...

like image 498
Viet Avatar asked Aug 08 '17 13:08

Viet


People also ask

How do I create an alias in Windows 10?

Console Aliases in Windows 10. To define a console alias, use Doskey.exe to create a macro, or use the AddConsoleAlias function.

Does bash have aliases?

An bash shell alias is nothing but the shortcut to commands. The alias command allows the user to launch any command or group of commands (including options and filenames) by entering a single word. Use alias command to display a list of all defined aliases. You can add user-defined aliases to ~/.

Where are git bash aliases?

These aliases were created with the --global flag which means they will be stored in Git's global operating system level configuration file. On linux systems, the global config file is located in the User home directory at /. gitconfig .


2 Answers

Try this:

  1. Open the bash terminal
  2. cd ~
  3. vi .bashrc
  4. press i to go edit mode and update it with you alias command.
  5. press Esc and press :wq(save and exit)
  6. now close and reopen the bash terminal
  7. check the alias command.

if this didn't work create the .bash_profile in the same way and add the line

if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
like image 152
skr Avatar answered Sep 20 '22 15:09

skr


you can also open and edit the file aliases.sh that you find in the installation path of git

C:\path where you installed Git\etc\profile.d\aliases.sh

Open it with atom or notepad++ and add a line like

alias MyProjectName='C:/<installation_path_of_your project>/'

and save.

close and reopen git bash

now if you write

MyProjectName

on Bash, it should automatically bring you tothe desired path.

If it doesn't work try with

cd MyProjectName
like image 31
Tms91 Avatar answered Sep 20 '22 15:09

Tms91