Tuesday, March 15, 2016

Git aliases: Shortening Git commands

So today we'll see, how we can shorten the long git commands, 
which can help programmers save time and a few keystrokes while working with git.

So lets work with git a bit. (Git a bit. Lol :p, a rhyming scheme. Does that help me qualify to be a poet, song writer?, umm... a rapper maybe? Maybe i should write a rap on this, yo mayne...! )


We'll see 2 ways of adding aliases to our git commands.


How to add aliases to git commands: 



Way 1: Using the `git config` command


Use the git config command to do the same.

So lets add an alias to the `status` command of git as `s`


git config --global alias.s status


Lets add another for `add`

git config --global alias.a add


Another for `commit`


git config --global alias.ci commit


And another


git config --global alias.cim "commit -m"


Now, we can just fire the short commands instead of the long ones and see the result of the command

for eg. git status, we can write,

git s


Lets break down the above command & take a look at the options we passed:

config: This option tells git, that everything following should be treated as the configuration for git, and can be added in the .gitconfig (or .git/config file depending on other options) file.


--global: The `--global` option tells git to add the alias in your '.gitconfig' which is in your home folder,

which will be treated as your global settings for all git repos on your system, 
unless you have another .git/config file inside a particular repo, overriding the global .gitconfig. 
Try using the `--global` option since it will help you keep the same aliases across all repositories on your system, if you have a number of them.
Without the `--global` option git will consider the local repository by default.
Caveat: If you already have the <short_name> as an alias to some other previsouly added command in the config, the --global option will replace that previous one.

alias.<short_name> <git_command_name>: Tells git that <git_command_name> particular command will have <short_name> as its alias form.



Way 2: Using the .gitconfig file directly


If you see in the ~/.gitconfig (~ = your_home_folder which is, /home/<your_login_name>/.gitconfig ) file,
you will notice that the shortened commands have gotten added under the [alias] section
Like this:




So instead of firing a `git config` command, lets try adding, the aliases directly into this file.


Lets open the file,


vim ~/.gitconfig


go under the [alias] section & type 


rl = reflog

& save it & the file now looks like this.




And now we can check the `reflog` command too, by typing
git rl

So, there we have it.

Let us know, if the above post was of any help to you.
Until later.


Oh ya! The complimentary rap i mentioned.


{

Rap starts...

Hey yo! Let me tell you a few things about git,

but i'll teach you them, uh! bit by bit.
aye! but, bit by bit, is a 1 bit. (Suddenly, the rapper gets into Math/CS/Binary mode & talks about, Division/Binary division, as, bit by bit, bit_divided_by_bit, is 1bit/1bit is 0b0001/0b0001 = 0b0001 = 1),
oh my gosh!!! what is this sh*t??? (And.. the audience go...). 

:-P

}

Monday, March 7, 2016

Working with Postgresql helper commands

Hi Friends,

So today we'll try to learn a few things on Postgresql and
see what exactly Postgresql 'Helper commands' are.

Apart from the good old sql queries that you can certainly use,
Postgresql also provides us with Helper commands which you can use
to fetch information from the Postgrsql DB.

You can fire the Postgresql Helper commands from the Postgresql command prompt.

So lets login into the Postgresql command prompt.
`psql` is the command line utility you would need for this, so lets begin.

Open Terminal (`ctrl+alt+t` in Ubuntu, check for you particular distro)

psql -h <host_name> -p <port_number> -d <database_name> -U <db_user_name> -W

Type in your db_password in the password prompt.

So now since we have connected to out database, lets see a few commands.

Check for All the Databases on the server
\l+

Check for size and access privileges of a particular Database
\l+ <database_name>

List Tables in a DB
\d

List Tables in a DB with Size
\dt+

Details about a particular table
\dt+ <table_name>

Describe a Table in a DB
\d+ <table_name>

Describe table with size and description (with pg_catalog schema)
\dtS+ <table_name>

Change/connect/move to a different Database.

\c <new_database_name>

Will try to come up with more blog post where we can share our information with each other.

Please let us know if you have any comments about the blog in the comments section below or if there are any corrections you may have spotted and you would like us to make those corrections.

Thanks a lot for taking your time & stopping over at the blogpost.
Have a good day!