Git Alias

·

2 min read

I know it is out there on the internet. You can find everything about git and git alias in so many places. It is not that...

My idea is to share the way I used it to save your time from completing the puzzle on your own.

Tools

I am using git bash .

The Tricks I Use

First, open Bash and enter:

cd
touch ~/.bash_profile
touch ~/.bashrc

This will navigate to the root user's directory, and create the bashrc file. The bashrc file will contain your custom shortcuts (alias) and probably some other functions.

To edit your bashrc file use any text editor you prefer. The file is located in your user's folder. For example: C:\users\myuser.bashrc

Paste the following inside and save:

alias reload='. ~/.bashrc'

Now enter in your bash file:

. ~/.bashrc

This will reload the commands in your bashrc file.

You can add some alias now into the bashrc file:

alias ga='git add .'
alias gst='git status'
alias gps='git push'

and save.

In your bash you can reload the new alias by entering "reload" command:

reload

Navigate in bash to your repository (replace with your repository path):

cd /c/repos/myrepo

Check your status using the alias gps:

gps

Functions

Add the following functions:

repo() {
    cd /c/repos/$1
}

sln() {
    s=`ls | grep .sln`
    start $s
}

Reload your changes

reload

Use repo to easily navigate to your repository path in bash:

repo myrepo

Use sln to easily open your Visual Studio solution:

sln

Conclusions

You can use any combination you want to create your own alias. Here are some of my examples:

alias reload='. ~/.bashrc'

alias ga='git add .'
alias gst='git status'
alias gps='git push'

alias gc='git commit'
alias gca='ga && gc'
alias gca-s='gca && gps'
alias gco='git checkout'
alias gpl='git pull'
alias gcopl='checkout_pull'

alias gcb='git branch --show-current'

alias gcom='gco master && gpl'

alias gmfm='merge_from_master'

merge_from_master () {
    cb=`gcb` && gcom
    gcopl $cb && git merge master && gps
}

repo() {
    cd /c/repos/$1
}

sln() {
    s=`ls | grep .sln`
    start $s
}