Home > Software design >  How to add create powershell aliases for git commands
How to add create powershell aliases for git commands

Time:02-09

I have been tired of doing git add & git commit everyday I know in Linux you can just edit your bashrc using 1 line command But since I use windows I am having a hard time creating an alias for

 Fucntion gcd {
    Insert("git commit")
}
Set-Alias gcm gcd

But I get an error

Set-Alias : Alias is not writeable because alias gcm is read-only or constant and cannot be written to.

I also tried without using Insert Keyword even without functions still getting an error

CodePudding user response:

Why don't you just try tu use posh-git

posh-git is a PowerShell module that integrates Git and PowerShell by providing Git status summary information that can be displayed in the PowerShell prompt, e.g.:

C:\Users\Keith\GitHub\posh-git [main ≡  0 ~1 -0 |  0 ~1 -0 !]>

posh-git also provides tab completion support for common git commands, branch names, paths and more. For example, with posh-git, PowerShell can tab complete git commands like checkout by typing git ch and pressing the tab key. That will tab complete to git checkout and if you keep pressing tab, it will cycle through other command matches such as cherry and cherry-pick. You can also tab complete remote names and branch names e.g.: git pull or ma tab completes to git pull origin main.

CodePudding user response:

You don't need to rely on your specific shell for aliases, since Git already supports them out of the box:

If you don’t want to type the entire text of each of the Git commands, you can easily set up an alias for each command using git config.

Git aliases are defined in the .gitconfig file, either globally or for a particular repository.

In your case, you can create a global alias for git commit by saying:

git config --global alias.gcd commit
  •  Tags:  
  • Related