How to set aliases in the Git Bash for Windows?

后端 未结 8 1685
渐次进展
渐次进展 2021-01-29 19:34

How to alias command in Git Bash for Windows downloaded from git-scm.com ?

I mean Bash commands not Git.

(windows7)


Edit:

Writing aliases i

相关标签:
8条回答
  • 2021-01-29 20:07
    • Go to: C:\Users\ [youruserdirectory] \bash_profile

    • In your bash_profile file type - alias desk='cd " [DIRECTORY LOCATION] "'

    • Refresh your User directory where the bash_profile file exists then reopen your CMD or Git Bash window

    Type in desk to see if you get to the Desktop location or the location you want in the "DIRECTORY LOCATION" area above

    Note: [ desk ] can be what ever name that you choose and should get you to the location you want to get to when typed in the CMD window.

    0 讨论(0)
  • 2021-01-29 20:10

    To Add a Temporary Alias:

    1. Goto Terminal (I'm using git bash for windows).
    2. Type $ alias gpuom='git push origin master'
    3. To See a List of All the aliases type $ alias hit Enter.

    To Add a Permanent Alias:

    1. Goto Terminal (I'm using git bash for windows).
    2. Type $ vim ~/.bashrc and hit Enter (I'm guessing you are familiar with vim).
    3. Add your new aliases (For reference look at the snippet below).
      #My custom aliases  
      alias gpuom='git push origin master' 
      alias gplom='git pull origin master'
      
    4. Save and Exit (Press Esc then type :wq).
    5. To See a List of All the aliases type $ alias hit Enter.
    0 讨论(0)
  • 2021-01-29 20:11

    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)

    0 讨论(0)
  • 2021-01-29 20:12

    Follow below steps:

    1. Open the file .bashrc which is found in location C:\Users\USERNAME\.bashrc

      If file .bashrc not exist then create it using below steps:

      1. Open Command Prompt and goto C:\Users\USERNAME\.
      2. Type command notepad ~/.bashrc
        It generates the .bashrc file.
    2. Add below sample commands of WP CLI, Git, Grunt & PHPCS etc.


    # ----------------------
    # Git Command Aliases
    # ----------------------
    alias ga='git add'
    alias gaa='git add .'
    alias gaaa='git add --all'
    
    # ----------------------
    # WP CLI
    # ----------------------
    alias wpthl='wp theme list'
    alias wppll='wp plugin list'
    

    Now you can use the commands:

    • ga instead of git add .
    • wpthl instead of wp theme list

    Eg. I have used wpthl for the WP CLI command wp theme list.

    Yum@M MINGW64 /c/xampp/htdocs/dev.test
    $ wpthl
    +------------------------+----------+-----------+----------+
    | name                   | status   | update    | version  |
    +------------------------+----------+-----------+----------+
    | twentyeleven           | inactive | none      | 2.8      |
    | twentyfifteen          | inactive | none      | 2.0      |
    | twentyfourteen         | inactive | none      | 2.2      |
    | twentyseventeen        | inactive | available | 1.6      |
    | twentysixteen          | inactive | none      | 1.5      |
    | twentyten              | inactive | none      | 2.5      |
    | twentythirteen         | inactive | none      | 2.4      |
    | twentytwelve           | inactive | none      | 2.5      |
    

    For more details read the article Keyboard shortcut/aliases for the WP CLI, Git, Grunt & PHPCS commands for windows

    0 讨论(0)
  • 2021-01-29 20:14

    Using Windows and MINGW64 GitBash ((mintty 3.2.0), i found the file under:

    C:\Users\<user name>\AppData\Local\Programs\Git\etc\profile.d\aliases.sh
    

    Just add the alias there and i worked for me

    0 讨论(0)
  • 2021-01-29 20:15

    I had the same problem, I can't figured out how to find the aliases used by Git Bash on Windows. After searching for a while, I found the aliases.sh file under C:\Program Files\Git\etc\profile.d\aliases.sh.

    This is the path under windows 7, maybe can be different in other installation.

    Just open it with your preferred editor in admin mode. After save it, reload your command prompt.

    I hope this can help!

    0 讨论(0)
提交回复
热议问题