Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It’s strange that git aliases can’t accept multiple git commands. It gives a strange divide between single command aliases which go in your git config and multi command aliases which go in a shell config. Shells vary and some don’t even have aliases (cmd is probably the most used shell of them all and it - almost - doesn’t have aliases at all).

Being able to define an && alias in .gitconfig would be great for being able to share snippets like these across shells and OS:es.

My most used alias is by far “git oops” for git commmit —all —-amend —-no-edit



You can absolutely put multiple commands in a single git alias. The comment you replied to even shows it.

There's no reason any of those couldn't be in a .gitconfig file.

Prepend the alias with ! it's executed via a shell. I use it to embed shell functions (which generally call git)

Eg an alias to show commits missing (useful when using cherry pick)

    show-missing-commits = "!show_missing_commits() { local target=\"${2:-$(git rev-parse --abbrev-ref HEAD)}\"; printf -- 'Showing commits present in \"%s\" but not \"%s\"\n' "$1" "$target"; git log --no-merges \"$1\" ^\"${target}\"; }; show_missing_commits"


I’m pretty sure that it’s shell specific whether it works precisely because it defers it to the shell. For windows cmd in particular it’s… not great.

What I mean is I’d like git to do it natively. But git was written assuming a posix shell and it shows up here and there sadly.

Example:

   git command1 —-flag1 <some_separator> command2 —-flag2
Should be possible for git to simply interpret sequentially.


> But git was written assuming a posix shell and it shows up here and there sadly.

Given that the entire point of POSIX is cross platform compatibility, this is one of the few times when I will say they (Linus/git) got it 100% right.

> Should be possible for git to simply interpret sequentially.

Simply? What should it do if the first command fails? Should it exit early? What if you want it to run the second only if the first returns error? What if you want to pipe the first to the second? Or use it as an argument?

Aliases have a "simple" mode where they call exactly one thing. Anything beyond that can't be simple, without also being useless.

If Microsoft can't ship a POSIX compatible shell that's on them, and if you insist on using an OS that doesn't have a POSIX compatible shell, that's on you.

I don't start Linux and ask why it doesn't run whatever people use Windows for... malware I assume?


> Simply? What should it do if the first command fails? Should it exit early? What if you want it to run the second only if the first returns error?

You’d eventually reinvent a shell. But for just these 2 cases you’d just need 2 separators analogous to the & and && of the shell. But yeah it gets messy if you wanted to run a non git command in the middle.

The thing is, all those !a && b are perfectly valid in both posix and cmd. It just refuses to do the whole “if it starts with ! call the shell”. I guess all that’s missing is that it just needs to execute it. That would probably be the less complicated change. That at least doesn’t seem like a big controversial addition (maybe this is already done now it was a couple of years since I tried and hit a brick wall with aliases under cmd)


More than that, it can run arbitrary non-git commands too: prefix with `!` to run in the shell instead of as arguments to `git`.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: