How to define Git commands Aliases

I want to introduce a feature that can make your Git experience simpler, easier, and more familiar: aliases or shorthands

Method 1:

Git doesn’t automatically infer your command if you type it in partially. If you don’t want to type the entire text of each of the Git commands, you can easily set up an alias for each command using git config. Here are a couple of examples you may want to set up:

Quick note:

On unix, use single quotes if the alias has a space:

On windows, use double quotes if the alias has a space or a command line argument:

The alias command even accepts functions as parameters. Take a look at aliases.

This means that, for example, instead of typing git commit, you just need to type git ci. As you go on using Git, you’ll probably use other commands frequently as well; don’t hesitate to create new aliases.

Method 2:

Basically you just need to add lines to ~/.gitconfig

You can copy and use this complete configuration for yourself:

This technique can also be very useful in creating commands that you think should exist. For example, to correct the usability problem you encountered with unstaging a file, you can add your own unstage alias to Git:

This makes the following two commands equivalent:

This seems a bit clearer. It’s also common to add a last command, like this:

This way, you can see the last commit easily:

As you can tell, Git simply replaces the new command with whatever you alias it for. However, maybe you want to run an external command, rather than a Git subcommand. In that case, you start the command with a ! character. This is useful if you write your own tools that work with a Git repository. We can demonstrate by aliasing git visual to run gitk:

ohmyzsh aliases: refere here

Posting daily about Python, Nuclear Physicist PhD