6

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.

1

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

Comments

6

You are almost there. You just need to put the alias in the right file. Because Git doesn’t automatically infer your command if you type it in partially, you can easily set up an alias for each command using git config like so:

git config --global alias.co checkout git config --global alias.br branch git config --global alias.ci commit git config --global alias.st status 

And then you use it the aliases like: git ci, git co, git br, git st in any repo.

You can also run an external command through an alias. 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:

git config --global alias.visual '!gitk' 

You might have also noticed that the config command takes in several parameters (like the --global one). If we look at the docs man git config:

For writing options: write to global ~/.gitconfig file rather than the repository .git/config, write to $XDG_CONFIG_HOME/git/config file if this file exists and the ~/.gitconfig file doesn’t. For reading options: read only from global ~/.gitconfig and from $XDG_CONFIG_HOME/git/config rather than from all available files. See also the section called “FILES”.

There is also --system, which writes to /etc/gitconfig, --local, for the local repo .git/gitconfig, and --worktree, which is similar to --local.

But you can just directly edit the files themselves. It will look similar to this:

# in ~/.gitconfig [alias] lg = log --all --stat --pretty=oneline --graph --format='%h %d %an %cr %s' --oneline l = log --all --stat --graph --format='%h %d %an %cr %s' up = pull --rebase br = branch --verbose -a sfp = push --force-with-lease 

Comments

2

You should set the alias in your git aliases and use it from the command line

You can directly edit the configuration file or do it from CLI:

Git Alias

Use the git config --global alias.<name> in order to add git alias

git config --global alias.l 'log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate' 

now you should be able to use it with: git l


Ubuntu Alias

If you wish to add an alias to your shell in Ubuntu:

alias gitl='git l' 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.