How to use Git Alias to increase your productivity (video)

How to use Git Alias to increase your productivity (video)

Last Updated on Nov 27, 2022

https://youtu.be/bUCIVgfs30o

 

Transcription

Hello

This is amir

Today we are going to talk about Git Alias and how to increase your productivity by adding shorter aliases for commands that we use everyday

So let’s get started

What is Alias

First of all, what are aliases?

Well aliases are like shortcuts for a command.

Instead of writing the full command you can just run the short version.

For example, Instead of writing

Git checkout master

You would write

Git com

The cool part is that you can combine multiple commands and give them an alias

For example you can combine

Git checkout master

and

Git add .

and

Git commit -m

To one command.

Enough teasing let’s see how we can do it

How to Add a git alias

In order to add a new alias, You should run this command:

git config --global alias.<your-alias> ‘<command>’

If you want the alias to work only for this project then remove the –global flag

And if the command you are aliasing starts with git add ! in the beginning

Examples

Let’s see some examples:

Example 1

I want to have com as the alias for

Git checkout master

And I only want this alias to work in this project so I won’t write the –global flag

Let’s do it

Git config alias.com ‘checkout master’

Or I could write the full command and add !

Git config alias.com ‘!git checkout master’

And let’s test it now

Git com

Perfect now we are in the master branch

Example 2

Second example is to see how we can combine multiple commands in one alias.

One of the things I use a lot is git add . and git commit

So I want to combine those to commands in an alias something like add-commit or acm 

Let’s do it now

git config alias.acm '!git add . & git commit -m'

Ok let’s test it

First let’s see the changed files by running

git status

And now let’s run our alias

git acm

Perfect it has added everything and committed everything

Awesome!

Practice

Let’s practice together

Question

I use this command a lot

git log -1 head

This shows only the last log

I want to make an alias for it with the name last

And I want this alias to run only in my local project not globally

How can I do it?

Pause the video

Try to do it

Write your answer in the comment and then play the video to see the answer

Answer

Ok now let’s see the answer.

we want to add a new alias called last and it shouldn’t be a global alias.

To do that we should run this command

Git config alias.last '!git log -1 head'

And let’s see if it works

Great it works!

Was your answer correct?

Key Takeaways

Just a quick recap

  • We talked about adding alias for git commands
  • We created an alias for a single command and we also combined multiple commands and gave them an alias

Final Words

And finally, if you liked what you learned please like and subscribe.

That would be a great motivation to do more videos.

If you have any suggestions or questions please leave a comment below and I try to answer them as soon as possible

That’s it

Have a wonderful day.

You can watch the original video on youtube.

Category: programming

Tags: #git

Join the Newsletter

Subscribe to get my latest content by email.

I won't send you spam. Unsubscribe at any time.

Related Posts

Courses