threads / discuss / 20060

default aliases (ci, di, st, co)

Subject: default aliases (ci, di, st, co)

## tl;dr

19 messages between Jul 8, 2009 and Jul 13, 2009.

replies: 18people: 11as markdown or json

Ondrej Certik· Jul 8, 2009, 23:49 UTC · lore
Hi,
coming to git from mercurial and svn, here is the alias part of my .gitconfig:
[alias]
    ci = commit
    di = diff --color-words
    st = status
    co = checkout

And all is fine until I share commands to checkout my branch (for example) with other people, then basically I have to write those commands in full (e.g. commit, checkout, ...), since I cannot assume they have their .gitconfig setup the same way I do. Especially for people who are new to git.

What is the view on this in the git community? Do most of you write
git checkout -b branch ...
(possibly with TAB completion) or do most of you write
git co -b branch ...
(like I do all the time, except when sharing my commands with other people)?

Could in principle those aliases be even made default by git? Or is this not a good idea.

Ondrej
Jakub Narebski· Jul 9, 2009, 00:13 UTC · re: Ondrej Certik · lore

Re: default aliases (ci, di, st, co)

Ondrej Certik <ondrej@certik.cz> writes:
Show 15 quoted lines
> coming to git from mercurial and svn, here is the alias part of my
> .gitconfig:
> 
> [alias]
>     ci = commit
>     di = diff --color-words
>     st = status
>     co = checkout
> 
> 
> And all is fine until I share commands to checkout my branch (for
> example) with other people, then basically I have to write those
> commands in full (e.g. commit, checkout, ...), since I cannot assume
> they have their .gitconfig setup the same way I do. Especially for
> people who are new to git.

If you have admin rights on the machine, you can do that either using system git config file (git config --system) i.e. $(prefix)/etc/gitconfig or rather $(sysconfdir)/gitconfig, or by providing 'config' template (copied as default repository config on init) in some place like /usr/share/git-core/templates/config .

Show 11 quoted lines
> 
> What is the view on this in the git community? Do most of you write
> 
> git checkout -b branch ...
> 
> (possibly with TAB completion) or do most of you write
> 
> git co -b branch ...
> 
> (like I do all the time, except when sharing my commands with other
> people)?

I use tab completion for commands like "git commit", "git show", "git checkout" etc. (most important part is branch completion, not command completion IMVHO).

But I do have few aliases:
[alias]
        cat  =    cat-file -p
        less = -p cat-file -p
        alias = config --get-regexp ^alias\\.
        lg = log --pretty=oneline --abbrev-commit
        one = show -s --pretty='format:%h (%s)'
        llog = log --date=local
        who = "!sh -c 'git log -1 --pretty=\"format:%an <%ae>\" --author=\"$1\"' -"
        lb = for-each-ref --format='%(refname)' \
             --sort=-authordate --count=8 refs/heads/
        rllog = log -g --date=relative
        rlg   = reflog show @{now}
        sed = !git ls-files --stage | grep ^100 | awk '{print $4}' | xargs sed

I use most often "git one" aliase (hmmm... I have just noticed that "git lg" alias is now superfluous with new '--oneline' option).

> Could in principle those aliases be even made default by git? Or is
> this not a good idea.

The "default/built-in aliases" idea was discussed on git mailing list a few times in the past...

-- 
Jakub Narebski
Poland
ShadeHawk on #git
Graeme Geldenhuys· Jul 9, 2009, 08:58 UTC · re: Jakub Narebski · lore

Re: default aliases (ci, di, st, co)

Jakub Narebski wrote:
>         one = show -s --pretty='format:%h (%s)'

I like that one. It's going to be very handy for when I post commit messages to my project newsgroup, as a subject title.

> I use most often "git one" aliase (hmmm... I have just noticed that
> "git lg" alias is now superfluous with new '--oneline' option).

:-) I only learned about --oneline yesterday myself and was going to mention that to you. You beat me to it.

Regards,
   - Graeme -
-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/
Junio C Hamano· Jul 9, 2009, 16:43 UTC · re: Jakub Narebski · lore

Re: default aliases (ci, di, st, co)

Jakub Narebski <jnareb@gmail.com> writes:
>         one = show -s --pretty='format:%h (%s)'

If you use "git one" for quoting a commit in the log message, please use a format that shows the date as well (I think I posted mine to the list in the past).

Paolo Bonzini· Jul 9, 2009, 23:08 UTC · re: Junio C Hamano · lore

Re: default aliases (ci, di, st, co)

On 07/09/2009 06:43 PM, Junio C Hamano wrote:
Show 7 quoted lines
> Jakub Narebski<jnareb@gmail.com>  writes:
>
>>          one = show -s --pretty='format:%h (%s)'
>
> If you use "git one" for quoting a commit in the log message, please use a
> format that shows the date as well (I think I posted mine to the list in
> the past).
Yes, it's in the wiki and in my .gitconfig:
         whatis = "!sh -c 'git show -s --pretty=\"format:%h (%s, %ai\" 
\"$@\" | sed -e \"s/ [012][0-9]:[0-5][0-9]:[0-5][0-9] 
[-+][0-9][0-9][0-9][0-9]$/)\\n/\"' -"
BTW, the wiki shows a nice trick to avoid the extra ' quotation:
         whatis = "!f() { git show -s --pretty='format:%h (%s, %ai' 
\"$@\" | sed -e 's/ [012][0-9]:[0-5][0-9]:[0-5][0-9] 
[-+][0-9][0-9][0-9][0-9]$/)\\n/'; }; f"
Paolo
Jeff King· Jul 13, 2009, 06:40 UTC · re: Paolo Bonzini · lore

Re: default aliases (ci, di, st, co)

On Fri, Jul 10, 2009 at 01:08:27AM +0200, Paolo Bonzini wrote:
Show 5 quoted lines
> Yes, it's in the wiki and in my .gitconfig:
> 
>         whatis = "!sh -c 'git show -s --pretty=\"format:%h (%s, %ai\"
> \"$@\" | sed -e \"s/ [012][0-9]:[0-5][0-9]:[0-5][0-9]
> [-+][0-9][0-9][0-9][0-9]$/)\\n/\"' -"
Is there a reason not to simply use:
  whatis = "show -s --pretty='format:%h (%s, %ad)' --date=short"
these days?
-Peff

P.S. Actually, I use --no-pager in my version, so I use 'tformat' to explicitly end it with a newline, which is nicer for actually showing the output on the terminal.

Jeff King· Jul 13, 2009, 06:43 UTC · re: Jeff King · lore

Re: default aliases (ci, di, st, co)

On Mon, Jul 13, 2009 at 02:40:27AM -0400, Jeff King wrote:
Show 19 quoted lines
> On Fri, Jul 10, 2009 at 01:08:27AM +0200, Paolo Bonzini wrote:
> 
> > Yes, it's in the wiki and in my .gitconfig:
> > 
> >         whatis = "!sh -c 'git show -s --pretty=\"format:%h (%s, %ai\"
> > \"$@\" | sed -e \"s/ [012][0-9]:[0-5][0-9]:[0-5][0-9]
> > [-+][0-9][0-9][0-9][0-9]$/)\\n/\"' -"
> 
> Is there a reason not to simply use:
> 
>   whatis = "show -s --pretty='format:%h (%s, %ad)' --date=short"
> 
> these days?
> 
> -Peff
> 
> P.S. Actually, I use --no-pager in my version, so I use 'tformat' to
> explicitly end it with a newline, which is nicer for actually showing
> the output on the terminal.

Er, actually, I see yours adds the newline explicitly in the sed invocation, so it would definitely be 'tformat' to match what yours does.

-Peff
Paolo Bonzini· Jul 13, 2009, 09:15 UTC · re: Jeff King · lore

Re: default aliases (ci, di, st, co)

On 07/13/2009 08:40 AM, Jeff King wrote:
Show 13 quoted lines
> On Fri, Jul 10, 2009 at 01:08:27AM +0200, Paolo Bonzini wrote:
>
>> Yes, it's in the wiki and in my .gitconfig:
>>
>>          whatis = "!sh -c 'git show -s --pretty=\"format:%h (%s, %ai\"
>> \"$@\" | sed -e \"s/ [012][0-9]:[0-5][0-9]:[0-5][0-9]
>> [-+][0-9][0-9][0-9][0-9]$/)\\n/\"' -"
>
> Is there a reason not to simply use:
>
>    whatis = "show -s --pretty='format:%h (%s, %ad)' --date=short"
>
> these days?
With s/format/tformat, which I just learnt about, no, there is no reason.
Thanks!
Paolo
Andreas Ericsson· Jul 9, 2009, 07:00 UTC · re: Ondrej Certik · lore

Re: default aliases (ci, di, st, co)

Ondrej Certik wrote:
Show 18 quoted lines
> Hi,
> 
> coming to git from mercurial and svn, here is the alias part of my .gitconfig:
> 
> [alias]
>     ci = commit
>     di = diff --color-words
>     st = status
>     co = checkout
> 
> 
> And all is fine until I share commands to checkout my branch (for
> example) with other people, then basically I have to write those
> commands in full (e.g. commit, checkout, ...), since I cannot assume
> they have their .gitconfig setup the same way I do. Especially for
> people who are new to git.
> 
> What is the view on this in the git community?

Personally I think "plain" aliases like you use above are evil. git is not svn or mercurial. If you use it like svn you'll be surprised sooner or later and your workflow will feel awkward or just plain wrong. hg and git are very similar, but the fact that hg assumed the svn shorthands implies to me that they've tried to retain a compatibility that does not, in fact, exist. DVCS systems are enormously different from centralized ones. Borrowing from centralized ones to a DVCS one feels utterly backwards.

Show 10 quoted lines
> Do most of you write
> 
> git checkout -b branch ...
> 
> (possibly with TAB completion) or do most of you write
> 
> git co -b branch ...
> 
> (like I do all the time, except when sharing my commands with other people)?
> 

I have no simple aliases for any of the commands. There's just no reason for them since tab completion works so well.

I do have one alias, which is "wsfix". It fixes whitespace fsckups I've added to the index but not yet committed to the worktree. It's not a particularly complex one, but not exactly simple either.

> Could in principle those aliases be even made default by git? Or is
> this not a good idea.
> 

I see no reason to add default aliases. It will make a mess of things when trying to explain workflows to people who have older versions of git where those default aliases aren't available. It'll add complexity to explanations, which is never a good thing.

If I have a vote, I vote no.
-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.
Michael J Gruber· Jul 9, 2009, 08:50 UTC · re: Andreas Ericsson · lore

Re: default aliases (ci, di, st, co)

Andreas Ericsson venit, vidit, dixit 09.07.2009 09:00:
Show 61 quoted lines
> Ondrej Certik wrote:
>> Hi,
>>
>> coming to git from mercurial and svn, here is the alias part of my .gitconfig:
>>
>> [alias]
>>     ci = commit
>>     di = diff --color-words
>>     st = status
>>     co = checkout
>>
>>
>> And all is fine until I share commands to checkout my branch (for
>> example) with other people, then basically I have to write those
>> commands in full (e.g. commit, checkout, ...), since I cannot assume
>> they have their .gitconfig setup the same way I do. Especially for
>> people who are new to git.
>>
>> What is the view on this in the git community?
> 
> 
> Personally I think "plain" aliases like you use above are evil.
> git is not svn or mercurial. If you use it like svn you'll be
> surprised sooner or later and your workflow will feel awkward or
> just plain wrong. hg and git are very similar, but the fact that
> hg assumed the svn shorthands implies to me that they've tried
> to retain a compatibility that does not, in fact, exist. DVCS
> systems are enormously different from centralized ones. Borrowing
> from centralized ones to a DVCS one feels utterly backwards.
> 
> 
>> Do most of you write
>>
>> git checkout -b branch ...
>>
>> (possibly with TAB completion) or do most of you write
>>
>> git co -b branch ...
>>
>> (like I do all the time, except when sharing my commands with other people)?
>>
> 
> I have no simple aliases for any of the commands. There's just no reason
> for them since tab completion works so well.
> 
> I do have one alias, which is "wsfix". It fixes whitespace fsckups I've
> added to the index but not yet committed to the worktree. It's not a
> particularly complex one, but not exactly simple either.
> 
> 
>> Could in principle those aliases be even made default by git? Or is
>> this not a good idea.
>>
> 
> I see no reason to add default aliases. It will make a mess of things
> when trying to explain workflows to people who have older versions of
> git where those default aliases aren't available. It'll add complexity
> to explanations, which is never a good thing.
> 
> If I have a vote, I vote no.
> 
Adding my no-vote to that, too.

Aliases are great, but default aliases are a problem. We saw this when we introduced "git stage", and I don't think we're happy in retrorespect.

Having said that, collecting useful aliases (e.g. one, who, ...) in contrib/ or in the wiki would be helpful.

Michael
Graeme Geldenhuys· Jul 9, 2009, 09:04 UTC · re: Michael J Gruber · lore

Re: default aliases (ci, di, st, co)

Michael J Gruber wrote:
> 
> Having said that, collecting useful aliases (e.g. one, who, ...) in
> contrib/ or in the wiki would be helpful.

+1 to that. I only spotted the 'one' alias now. So simple yet very handy. :-)

Regards,
   - Graeme -
-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/
Jakub Narebski· Jul 9, 2009, 09:40 UTC · re: Michael J Gruber · lore

Re: default aliases (ci, di, st, co)

On Thu, 9 July 2009, Michael J Gruber wrote:
[...]
Show 6 quoted lines
> Aliases are great, but default aliases are a problem. We saw this when
> we introduced "git stage", and I don't think we're happy in
> retrorespect. 
> 
> Having said that, collecting useful aliases (e.g. one, who, ...) in
> contrib/ or in the wiki would be helpful.
http://git.or.cz/gitwiki/Aliases
-- 
Jakub Narebski
Poland
Michael J Gruber· Jul 9, 2009, 09:48 UTC · re: Jakub Narebski · lore

Re: default aliases (ci, di, st, co)

Jakub Narebski venit, vidit, dixit 09.07.2009 11:40:
Show 12 quoted lines
> On Thu, 9 July 2009, Michael J Gruber wrote:
> 
> [...]
>> Aliases are great, but default aliases are a problem. We saw this when
>> we introduced "git stage", and I don't think we're happy in
>> retrorespect. 
>>
>> Having said that, collecting useful aliases (e.g. one, who, ...) in
>> contrib/ or in the wiki would be helpful.
> 
> http://git.or.cz/gitwiki/Aliases
> 

Thanks, I know, I added "git serve" a long time ago. I guess my use of "would" was quite misleading.

Michael
Luciano Miguel Ferreira Rocha· Jul 9, 2009, 08:58 UTC · re: Andreas Ericsson · lore

Re: default aliases (ci, di, st, co)

On Thu, Jul 09, 2009 at 09:00:30AM +0200, Andreas Ericsson wrote:
Show 23 quoted lines
>  Ondrej Certik wrote:
> > Hi,
> > coming to git from mercurial and svn, here is the alias part of my 
> > .gitconfig:
> > [alias]
> >     ci = commit
> >     di = diff --color-words
> >     st = status
> >     co = checkout
> > And all is fine until I share commands to checkout my branch (for
> > example) with other people, then basically I have to write those
> > commands in full (e.g. commit, checkout, ...), since I cannot assume
> > they have their .gitconfig setup the same way I do. Especially for
> > people who are new to git.
> > What is the view on this in the git community?
> 
> 
>  Personally I think "plain" aliases like you use above are evil.
>  git is not svn or mercurial. If you use it like svn you'll be
>  surprised sooner or later and your workflow will feel awkward or
>  just plain wrong. hg and git are very similar, but the fact that
>  hg assumed the svn shorthands implies to me that they've tried
>  to retain a compatibility that does not, in fact, exist.
No, it just means that shorting common commands is useful and common.
>  I have no simple aliases for any of the commands. There's just no reason
>  for them since tab completion works so well.
"Intelligent" bash completion always gets in my way, so I can't use it.
I vote yes.
-- 
Luciano Rocha <luciano@eurotux.com>
Eurotux Informática, S.A. <http://www.eurotux.com/>
Ondrej Certik· Jul 12, 2009, 05:07 UTC · re: Luciano Miguel Ferreira Rocha · lore

Re: default aliases (ci, di, st, co)

On Thu, Jul 9, 2009 at 2:58 AM, Luciano Miguel Ferreira Rocha<luciano@eurotux.com> wrote:

Show 33 quoted lines
> On Thu, Jul 09, 2009 at 09:00:30AM +0200, Andreas Ericsson wrote:
>>  Ondrej Certik wrote:
>> > Hi,
>> > coming to git from mercurial and svn, here is the alias part of my
>> > .gitconfig:
>> > [alias]
>> >     ci = commit
>> >     di = diff --color-words
>> >     st = status
>> >     co = checkout
>> > And all is fine until I share commands to checkout my branch (for
>> > example) with other people, then basically I have to write those
>> > commands in full (e.g. commit, checkout, ...), since I cannot assume
>> > they have their .gitconfig setup the same way I do. Especially for
>> > people who are new to git.
>> > What is the view on this in the git community?
>>
>>
>>  Personally I think "plain" aliases like you use above are evil.
>>  git is not svn or mercurial. If you use it like svn you'll be
>>  surprised sooner or later and your workflow will feel awkward or
>>  just plain wrong. hg and git are very similar, but the fact that
>>  hg assumed the svn shorthands implies to me that they've tried
>>  to retain a compatibility that does not, in fact, exist.
>
> No, it just means that shorting common commands is useful and common.
>
>>  I have no simple aliases for any of the commands. There's just no reason
>>  for them since tab completion works so well.
>
> "Intelligent" bash completion always gets in my way, so I can't use it.
>
> I vote yes.

Thanks everyone for contributing to the discussion. So it seems that most people are against such aliases.

I only want to correct one thing --- I use git exactly because it's not svn and exactly because it's not mercurial, things like git branches, git remote branches, rebase -i, are still truly unique, and in my experience once one tries it, he never wants to come back.

That said, I do use "git ci" and "git st" very often and I don't think it infers any kind of workflow. TAB completion doesn't help, because I need to write "git stat<TAB>", e.g. I save exactly one letter., commit is better, there I just need "git com<TAB>", but I am still faster with my aliases. Maybe "git co" is nasty, but I never had any problems with that either.

Ondrej
Graeme Geldenhuys· Jul 9, 2009, 09:01 UTC · re: Ondrej Certik · lore

Re: default aliases (ci, di, st, co)

Ondrej Certik wrote:
Show 6 quoted lines
> [alias]
>     ci = commit
>     di = diff --color-words
>     st = status
>     co = checkout
> 

I also gave from SVN and I must admit, I did create co, st, ci aliases, but basically never used them, so removed them since. Git is not SVN, so why treat it as such.

Alternatively, you can put your alias somewhere on a wiki or personal web page and just refer user to look at your alias list, instead of having to explain to them every time why your git commands are non-standard. It might save you some time and effort - in the long run.

Or just learn the full git commands. ;-)
Regards,
   - Graeme -
-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/
Matthieu Moy· Jul 9, 2009, 09:12 UTC · re: Graeme Geldenhuys · lore

Re: default aliases (ci, di, st, co)

Graeme Geldenhuys <graemeg@gmail.com> writes:
Show 11 quoted lines
> Ondrej Certik wrote:
>> [alias]
>>     ci = commit
>>     di = diff --color-words
>>     st = status
>>     co = checkout
>>
>
> I also gave from SVN and I must admit, I did create co, st, ci
> aliases, but basically never used them, so removed them since. Git is
> not SVN, so why treat it as such.

co is indeed particularly nasty. Yes, it's common for cvs/svn old-timers, but "co" is a prefix of "COmmit", and means "CheckOut". That's really misleading.

And the problem with aliases is that although they are good for personnal use, they become bad when people use them publicly : either in mail messages or in scripts. Ask about something that requires "git commit" on the Git mailing list, everybody will be talking about "git commit", not one about "git ci", the other about "git checkin" and the last one about "git commit". That's far less misleading (yes, the example is oversimplified, but if I advise someone to use "git diff --color-words", he/she understands what I'm talking about immediately, while if I advise "git di", it requires more time).

One thing I'd like to see is a wizard that creates a ~/.gitconfig with this section commented out when it does not exist, like

[alias] # Aliases, uncomment the lines to use them. # ci = commit # di = diff --color-words

To reduce the effort of people willing to use aliases, without making them totally official.

-- 
Matthieu
Andreas Ericsson· Jul 9, 2009, 20:54 UTC · lore

wsfix alias

Larry D'Anna wrote:
Show 8 quoted lines
> * Andreas Ericsson (ae@op5.se) [090709 03:04]:
>> I do have one alias, which is "wsfix". It fixes whitespace fsckups I've
>> added to the index but not yet committed to the worktree. It's not a
>> particularly complex one, but not exactly simple either.
> 
> oooh, i can has?
> 
>       --larry

These are quite stupid and can lose data for you. Please use with some care. Oh, and I lied. I have two aliases. wsfixi is the one that applies staged stuff. wsfix fixes all whitespace errors since the last commit and stages all changes in the index. Again, use with care, and don't hang me if they break your day ;-)

Mind the wrapping if your mua does things like that.
[alias]
  wsfix = !git diff HEAD >P.diff && git reset --hard && git apply --whitespace=fix P.diff && rm -f P.diff
  wsfixi = !git diff --cached >P.diff && git reset && git apply --whitespace=fix P.diff && rm -f P.diff
-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.
Larry D'Anna· Jul 9, 2009, 21:30 UTC · re: Andreas Ericsson · lore

Re: wsfix alias

* Andreas Ericsson (ae@op5.se) [090709 16:54]:
Show 21 quoted lines
> Larry D'Anna wrote:
>> * Andreas Ericsson (ae@op5.se) [090709 03:04]:
>>> I do have one alias, which is "wsfix". It fixes whitespace fsckups I've
>>> added to the index but not yet committed to the worktree. It's not a
>>> particularly complex one, but not exactly simple either.
>>
>> oooh, i can has?
>>
>>       --larry
>
> These are quite stupid and can lose data for you. Please use with some care.
> Oh, and I lied. I have two aliases. wsfixi is the one that applies staged
> stuff. wsfix fixes all whitespace errors since the last commit and stages
> all changes in the index. Again, use with care, and don't hang me if they
> break your day ;-)
>
> Mind the wrapping if your mua does things like that.
>
> [alias]
>  wsfix = !git diff HEAD >P.diff && git reset --hard && git apply --whitespace=fix P.diff && rm -f P.diff
>  wsfixi = !git diff --cached >P.diff && git reset && git apply --whitespace=fix P.diff && rm -f P.diff
a safer one: 
xargs -0 -I: <<'EOF' git config --file ~/.gitconfig alias.wsfix :
!
. "$(git --exec-path)"/git-sh-setup
if git-diff --quiet --exit-code; then
    if git diff --cached --check >/dev/null; then
        exit 0;
    fi
    echo fixing
    git diff --cached > $GIT_DIR/wsfix.diff
    git apply -R $GIT_DIR/wsfix.diff
    git apply --whitespace=fix $GIT_DIR/wsfix.diff
    rm -f $GIT_DIR/wsfix.diff
else
    echo wokring tree is dirty\!
fi
EOF
        --larry

← back to recent threads