loading...

Git 001 ~Add Alias to .gitconfig~

kojikanao profile image Koji (he/him) ・1 min read

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>

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

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

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

Now we can type the following

$ g b -m <new_name>

Alt Text

@rmnvsl thank you for your suggestion!

Posted on by:

kojikanao profile

Koji (he/him)

@kojikanao

Looking for opportunities! Software Engineer in NYC/Research Resident@NYU-ITP18-19 Mostly I work with reactjs and sometimes python. code to do something weird/useless/helpful Japanese

Discussion

markdown guide
 

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 ;)

 
[alias]
    ci = commit
    co = checkout
    up = push
    master = checkout master
    last = log -3 HEAD --decorate