Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git subcommand VS git --option

Tags:

git

git stash list >> will list all the stashes

git tag --list >> will list all the tags

but why it is "list" in the first command and "--list" in the second command? It is confusing for me (say you do "git tag list", then you actually create a tag called "list"). Does this apply for "stash" commands only(as all stash commands seem to be without --)? What is the logic behind this?

Edit:

after Charles Bailey reply I found that it is better to give the question more general sense so it becomes more useful. So, is there any convention used by git to distinguish between "subcommands" (like git stash list) and "options" (like git tag --list)?

thanks for contribution

like image 925
Alaa Avatar asked Apr 15 '13 12:04

Alaa


People also ask

What is a git subcommand?

Git subcommands are standalone executables that live in the Git exec path, normally /usr/lib/git-core. The git executable itself is a thin wrapper that knows where the subcommands live, and runs them by passing command-line arguments to them.

What does option in git?

If the option --all or -a is given, all available commands are printed on the standard output. If the option --guide or -g is given, a list of the useful Git guides is also printed on the standard output. If a command, or a guide, is given, a manual page for that command or guide is brought up.

What is a subcommand CLI?

Subcommands are keyword that invoke a new set of options and features. For example, the git command has a long series of subcommands, like add and commit . Each can have its own options and implementations.


2 Answers

I would say that the reason for this is because git tag takes an argument -- as opposed to a subcommand -- which should be able to be called anything you want. You should definitely be able to call a tag "list" if you so choose. Therefore git tag must hide its "subcommands" (or options) behind flags instead of subcommands.

The arguments to git stash are more strictly defined, so it is able to use true subcommands.

like image 183
Victor Zamanian Avatar answered Sep 21 '22 14:09

Victor Zamanian


I'd say it's simply that the English word tag can be used as a verb, so it feels natural to say git tag v1 and expect it to actually tag the current checkout v1.

The thing is, you can add aliases to make just about any syntax you want. When you get tired of typing git checkout in full, make an alias. Try searching for handy git aliases.

like image 27
jthill Avatar answered Sep 22 '22 14:09

jthill