bashgitaliasaliases

Creating git aliases


I am trying to add the following aliases in ubuntu

alias l=log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short

$ source ~/.aliases
bash: alias: --decorate: not found
bash: alias: --decorate: not found
bash: alias: --numstat: not found

I could use this command outside with git

I am not so sure why? Can someone help me? I tried googling but I did not go far with it. I do not know bash so much.


Solution

  • This is bit older question but it is very important to understand and create git alias as this will save lot of time of yours.

    In your question you are close to answer just a silly mistake done is you are trying to create alias using script.

    Alias needs to be defined in .gitconfig file. Not just alias but all config part like

    [core], [color], [pack], [help], [alias] etc

    I would like to share some basic and useful alias with you to have things handy and you can change it further per your need and daily usage

    [alias]
        lg = log -p
        lol = log --graph --decorate --pretty=oneline --abbrev-commit
        lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
        st = status
        co = checkout
        ci = commit -a -m
        br = branch
        ls = ls-files
        po = push origin
        f = fetch
        p = pull
        delete = branch -d master
        com = checkout master
        cob = checkout -b
        unstage = reset HEAD
        url = remote set-url origin 
        ign = ls-files -o -i --exclude-standard
        cp = cherry-pick
    

    You can also create an alias for a combination of multiple git commands in a single one as, for instance:

    rdev = !git checkout dev && git pull && git checkout - && git rebase dev
    

    Let me know if any other understanding needed.