Thursday, May 13, 2021

GIT Basics - Alias

 Alias are very important. When we create long commands, probably custom command as per our needs we can create an alias an use those.

git status

clean


git log --all --graph --decorate --oneline


this command is too long. If we can have a more shorter command , that's great

1. first let's look availability of the command 

Simply type that command and try, if  not found then we can use

eg:

git hist

git: 'hist' is not a command. 'git --help'

verified. we can use this as a new command

2. lets' look at create command for this long one, Alias

your command will be config "alias.{commandName}" and followed by "full command" within double quotes

git config --global alias.hist "log --all --graph --decorate --oneline"

git hist  --> you will have exact output as previous

3. Edit Alias

mate ~/.gitconfig

This will open config file in mate(macOS)

[user]

name = Alex Furr

email = af@email.com

[core]

editor = mate -w 

[alias]

hist = log --all --graph --decorate --oneline

Now if you need you can modify. eg: remove --graph and save

New 'hist' command will not have 'graph' part

No comments:

Post a Comment