Here are a bunch of aliases I use to work with git in command line.
Bash
For the bash it is simple, just copy and paste them into your ~/.bash_aliases
alias gfmp='git fetch -p && git checkout master && git pull'
alias ga='git add'
alias gd='git diff'
alias gdi='git diff --ignore-cr-at-eol'
alias gc='git commit'
alias gs='git status'
alias gpl='git pull'
alias gps='git push --all'
alias gl='git log --oneline --decorate --graph --all'
alias gld='git log --format="%C(auto)%h %d %ad %<(10,trunc)%al %s" --graph --all --date="format:%Y-%m-%d %H:%M"'
And you can use gfmp
to git fetch, checkout master and pull, and some others like gl
for git
log.
Powershell
With powershell it is a bit harder to configure. Powershell aliases do not support passing parameters.
You cannot assign an alias to a command and its parameters. For example, you can assign an alias to the Get-Eventlog cmdlet, but you cannot assign an alias to the Get-Eventlog -LogName System command.
As a workaround we can use functions. Let’s create a profile which is automatically run in every new powershell window and add there our new functions:
PS> New-Item -Type file -Path $PROFILE -Force
PS> notepad.exe $PROFILE
Add the following lines into the editor and save:
# Removing default aliases provided by Powershell, as they conflict with my new aliases for git
# Remove-Alias` does not work, as they are "constant or read-only".
Remove-Item -Force Alias:gc
Remove-Item -Force Alias:gl
Remove-Item -Force Alias:gps
function gfmp{git fetch -p; git checkout master; git pull}
# @args you can pass multi arguments for example
# ga fileName1 fileName2
function ga{git add @args}
function gd{git diff}
function gdi{git diff --ignore-cr-at-eol}
function gc{git commit}
function gs{git status}
function gpl{git pull}
function gps{git push --all}
function gl{git log --oneline --decorate --graph --all}
function gld{git log --format="%C(auto)%h %d %ad %<(10,trunc)%al %s" --graph --all --date="format:%Y-%m-%d %H:%M"}
Now when you start the new powershell window, you will be able to use the new aliases for git.
comments powered by Disqus