Creating aliases in PowerShell for git commands?

后端 未结 5 1001
遥遥无期
遥遥无期 2021-01-30 08:42

I understand how to create aliases in PowerShell for cmdlets fine, but I want to create an alias in PowerShell for things like git status as just gs, a

5条回答
  •  再見小時候
    2021-01-30 09:14

    You will have to create a function first, that has your command in it. Then create an alias to that function.

    PS C:\Users\jpogran\code\git\scripts> function get-gitstatus { git status }
    
    PS C:\Users\jpogran\code\git\scripts> get-gitstatus
    # On branch master
    nothing to commit (working directory clean)
    
    PS C:\Users\jpogran\code\git\scripts> Set-Alias -Name gs -Value get-gitstatus
    
    PS C:\Users\jpogran\code\git\scripts> gs
    # On branch master
    nothing to commit (working directory clean)
    

    You might also be interested in the OS project called posh-git that aims to provide a powershell environment for git commands. Wraps git commands with PS type functions and also provides a new prompt that shows the status and branch in your prompt.

    EDIT: Forgot to add how to find out how to do this using Powershell.

    PS C:\Users\jpogran\code\git\scripts> get-help set-alias -examples
    

    This will show you examples (the last one applies here) of how to use set-alias to create aliases to commands with paramaters, pipelines, etc.

提交回复
热议问题