DEV Community

0xkoji
0xkoji

Posted on

Git 001 ~Add Alias to .gitconfig~

I'm using iTerm and Github Desktop to use Git and Github since sometimes don't want to type any commands to work with Github.

However, sometimes prefer typing commands instead of clicks lol.

For example,

When I want to rename a branch, I need to click branch > rename and rename the branch then click Rename. On the other hand, with iTerm I just need to type the following. Actually, there is the shortcut for rename, but I don't remember that 😝

$ git branch -m <new_name>
Enter fullscreen mode Exit fullscreen mode

The command isn't long, but people who are a software engineer, developer web engineer, web developer are basically lazy. (My first CTO told me that engineers/developers should be lazy)

So what we need to do is to shorten commands as much as possible 😂

In terms of git commands what we can do is the followings.

  1. git --> g
  2. add aliases to .gitconfig for branch --> b

Actually, you can add gb as git branch, but I feel using .gitconfig could be better

Step 1
Add the following to your .zshrc, .bashrc etc.

alias g='git
Enter fullscreen mode Exit fullscreen mode

Step 2
Add the followings to .gitconfig The file is in your home folder

[alias]
    # basic commands
    b = branch
    p = push
    c = commit
    cm = commit -m
    f = fetch
    s = status
    st = stash
    rh = reset --hard
# update
    m = merge
    l = log
    last = log -3 HEAD --decorate
Enter fullscreen mode Exit fullscreen mode

The last one is from @vlasales, thank you for your comment!

Now we can type the following

$ g b -m <new_name>
Enter fullscreen mode Exit fullscreen mode

Alt Text

@rmnvsl thank you for your suggestion!

Top comments (3)

Collapse
 
rmnvsl profile image
Roman VeselĂ˝

GitHub aliases are really helpful, especially when you want to dig deeper with git log.

Your GIF is huge (6.5MB), try to resize it or capture smaller part of the screen ;)

Collapse
 
vlasales profile image
Vlastimil Pospichal
[alias]
    ci = commit
    co = checkout
    up = push
    master = checkout master
    last = log -3 HEAD --decorate
Collapse
 
0xkoji profile image
0xkoji

nice!
I should add log