tags:

views:

99

answers:

3

Hi,

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" and "git pull origin master" as "gpm" can anyone point me in the right direction?

I am sure I am missing something obvious.

Many thanks

Richard

+3  A: 

I don't know PowerShell, but you can setup aliases directly in Git.

Julien Nicoulaud
+4  A: 

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.

James Pogran
Bonus points for adding the git functions+aliases in a standalone script, and having them sourced in from your profile.
Goyuix
A: 

You need to create a profile.ps1 file put it in a folder call WindowsPowerShell in my documents

Then put in profile.ps1 a line like this:

set-alias wit 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\witadmin.exe'
Alex