Hacker News new | past | comments | ask | show | jobs | submit login
Git git git git git (caiustheory.com)
510 points by caiusdurling on Sept 26, 2017 | hide | past | web | favorite | 233 comments

>I quite often type git then go away and come back, then type a full git status after it.

Does anyone else actually do this besides OP. I've never heard of this problem until now.

I do. And I also write "vim vim thefile.txt" and stuff like that.

Finally I've written a small shell function that corrects "gi tpull" to "git pull", because that happens at least once a day.

I always typed rebnoot, so I patched Netbsd to allow rebnoot. Then I patched it still so it would say, "Rebnooting". Fun times.

Relatable. For years, I aliased mroe to more. Now I alias mroe and more to less.

My wife drafts a lot of legal documents, and has a problem with "doe snot". Which unfortunately the spelling checker is perfectly happy with.

There's defintitely room for an advanced spell checker that can say "This is valid, but probably wrong".

I just ran across Language Tool[0] recently. Free, open-source proofreading lib, can be run totally locally. Uses Google Ngrams to check for often confused words. Didn't correct "doe snot" in my synthetic test just now, but that seems like a plausibly minor extension of existing functionality.

[0] https://www.languagetool.org/

There’s at least one product trying to address the issue with “valid, but probably wrong” typos. It’s called Grammarly and for some unfathomable reason it gets advertised to me a lot on YouTube whenever Google detects I’m in South Korea; I believe they are seriously mistargeting their marketing efforts.

(That said, if it were me, I’m not sure if I would give up typing doe snot every once in a while.)


The spell checker in Chrome can already do that to some extent. For example, "The men walked over their to grab they're food." gets corrected: https://i.imgur.com/NR4zyVA.png

command-not-found [1] could implement that, if it isn't implemented already. I remember a Linux distribution with an application which would let a train pass in a few seconds after typing typical commands wrong. Trust me, you'll learn to type correct when that happens because it is very annoying.

EDIT: as mentioned below, it is called 'sl'

[1] https://wiki.ubuntu.com/CommandNotFoundMagic

The spelling checker in Word has some grammar rules, try to configure those if she uses Word.


My standard .bashrc aliases cd.. and cd- to the same thing with a space. Eliminating minor annoyances and focus-disruptors is great.

Our org has a bunch of related miscellaneous projects called "pantry". Basically, if it doesn't fit standalone, you put it in the pantry. It works out better than you think, except when someone is doing a webex and misses an r.

"Rebnooting" sounds like it should be a real word; probably a military term.

Can't tell if serious...

Knowing software developers, probably entirely serious.

The seasoned sysadmins are a little more careful before smacking the enter key...

Depends on the importance of the system. If it's a fairly unimportant home system that's excessively backed up, it's fairly easy to live life on the edge.

rm -i and rm -f (as well as mv and cp) allow to specify certainty not merely for everyone above UID 0.

Keyword: Backups.

It’s probably just a shell script or an alias

An alias would work but it wouldn't say rebnooting. That was my initial fix. But I was learning things at the time and I learned how to recompile parts of the distribution. I also learned how programs in Unix could invoke different effects based on name. Coming from DOS, it was a real surprise that reboot was a link to shutdown.

So I am assuming you ended up patching the `shutdown` binary to print `Rebnooting` if exec'd with the `rebnoot` name?

This is similar to how busybox binary implements a bunch of the tools from coreutils etc.

I have The Fuck because I think the premise is hilarious, though I don't use it as much as I'd like since it's kind of slow for me...

It's apparently grown an "instant mode" which goes much faster: https://github.com/nvbn/thefuck/blob/master/README.md#experi...

Personally, I don't want my typos corrected when I enter commands. I prefer the negative reinforcement to encourage fewer errors. I also don't mind an occasional error.

Not hatin. Just wondering if I'm alone.

You probably aren't alone, since commands that punish you when you mistype exist. Check out sl[0] or gti[1].

[0] https://github.com/mtoyoda/sl [1] http://r-wos.org/hacks/gti

Ha -- both are amusing.

I'm the same, though I create tiny aliases for commonly typed commands. gp = "git pull", and so on.

It's not only commands. My spelling skills took a dive, as google got better and better in guessing what I actually want to search for.

Can you disable that feature somewhere ? The suggestion is good, but automatically doing the corrected query is not!

For the latter, https://github.com/nvbn/thefuck is great and pretty satisfying to use.

(me earlier this month: https://twitter.com/sailoremo/status/908390247548911617)

If debian ever starts shipping with a util called "gi", I'm screwed!

Depending on how the scritp is written, you're screwed only if it comes with a tpull command.

`alias gi="rm -rf /"`



Suicide git


Yes! I do all of those things too. git git, vim vim, and 'gi tpull' and 'gi tpush' and everything.

I think any command where you might start to type something out, but then need to refer to another window or session to figure out what else you want to type, is vulnerable to this kind of mistake.

Got a weird idea reading this. How about checking for all 127 error codes returned by $? (this is the return code that the shell gets, following a failed command, due to command not found).

This process should happen behind the scenes. And then train a RNN for translating it to the following command, which returns a success code. Perhaps, we need to add a few checks that successful command has the same intent as the one which returned 127 error code to the shell.

I just alias 'pull' to git pull, it's much nicer. Also 'push' and a few of the other most common ones.

Or alias to gp, gl, gd, ga, gmv, grm, gsh, glg, gcm, gcam, gpuo, gdwd, gpuom, ...

You're joking but...

    alias g='git status -sb'
    alias ga='git add'
    alias gac='git commit --amend'
    alias gb='git branch'
    alias gbb='git checkout -b'
    alias gbm='git branch --merged'
    alias gbn='git branch --no-merged'
    alias gc='git commit -m'
    alias gcp='git cherry-pick'
    alias gco='git checkout'
    alias gd='git diff'
    alias gdc='git diff --cached'
    alias gg='git status'
    alias gl='git log --graph --pretty=format:"%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset" --abbrev-commit'
    alias gla='git log --all --graph --pretty=format:"%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset" --abbrev-commit'
    alias ggpublish='git push && git push --tags && npm publish'
    alias gp='git pull --rebase && git push'
    alias gpp='git push && git push --tags'
    alias gpl='git pull --rebase --prune'
    alias gpt='git pull --rebase && git push --tags'
    alias grb='git rebase'
    alias grc='git rebase --continue'
    alias gsp='git stash ; gp ; git stash pop'
    alias unfuckgitremote='git branch --set-upstream-to=origin/`git rev-parse --abbrev-ref HEAD` `git rev-parse --abbrev-ref HEAD`'
I have to admit I use `unfuckgitremote` more often than you'd hope.

Instead of `unfuckgitremote`, why not just use `git push -u`?

origin head


If only there was a git shell...

There is, but it's just a restricted login shell. I see what you mean though

I put my most common git commands on keyboard macros mostly for this reason.

alias p='git pull'

why type 8 characters 100 times a day, when you can type 1?

I often type "git clone ", then switch to a browser to copy/paste the URL, which is usually fine, but there are still many times where I've happened to include "git clone" in the copied string. (So I end up with "git clone git clone $URL").

<Insert obligatory "don't ever paste into a CLI because $SECURITY and then admit that I've done the same thing.>

I think that advice got warped/lost in translation: Wasn't the original advice "dont't paste stuff copied from web pages into the CLI"? - Because a bad page could covertly change what is actually copied via JS.

That danger doesn't apply when things are copied from the browser chrome (address bar) or other locations. So why would pasting then still be dangerous?

I think blindly passing on advices "because $SECURITY" can actually detrimental to security because you may end up with half a dozen esoteric practices without actually knowing what they defend against. (I know the parent was half-joking, I think that's a more general problem)

You don't even need JS. In French and in style:

    <p>un paragraphe <span style="font-size: 0;">pas si </span>innocent</p>
So disabling JS won't protect you from those.

Most shells now support a bracketed paste mode. zsh: https://github.com/zsh-users/zsh/commit/98687fa1dec803f041cb..., bash: https://www.gnu.org/software/bash/manual/html_node/Readline-... (enable-bracketed-paste)

iTerm gives you a warning if it thinks you just pasted in something malicious

I think it gives warning when you paste something ends with a `\n`.

I think my zsh does something to detect copy paste (and not execute the command till I press enter), or it could be iTerm, no idea.

Happens to me too!

The one I do is `git clone ` then paste in the repository URL from bitbucket, and end up with `git clone git clone https://....`

I don't think that can be solved here though.

I do that all the time, often with package managers (npm install npm install foo)


Nice! Never knew about CTRL+u. Thanks.

It's so far from my left hand I prefer to press ctrl+w twice. (yes, I use the mouse a bit too much)

Hah! Bitbucket drives me nuts in many ways but this one truly is the worst!

Certainly. The user is either used to typing "git clone" or is using a GUI where you input the repo URL. How bitbucket does it would only be fine if you only use bitbucket or if everybody did it that way.

Not this, but I do fairly often think assume I'm in vim when I'm not.

`alias :q="echo NOT IN VIM!!!"`

My favorite one of these is typing ctrl-w (cut in emacs) in a browser tab as I am editing a bunch of text in a text box.

I use vimperator, so the only program I use a lot which still doesn't recognize ctrl+w is Hexchat.

My friends have gotten used to see me part the channel and rejoin shortly after, cursing my fingers.

Hexchat closing on C-w is such a pain! It can't be scripted away either because it's hardcoded in the source. I haven't looked into this for some time but there does seem to have been some updates.


That sounds like the kind of thing that would be really easy to maintain your own fork for...

HexChat parting on Ctrl+w is probably one of the main reasons that drove me to use a TUI IRC client like weechat.

You can try Lazarus form recovery[1] to mitigate your pain. It locally saves the content of forms and allows you to pull it back.

[1] https://addons.mozilla.org/en-US/firefox/addon/lazarus-form-...

Heh, for me ctrl-w means "extend selection to enclosing expression", which leads to the same issue in browsers.

One of the things I appreciate about macOS is that it implements some of the emacs behavior (C-a, C-e, C-k). Unfortunately not C-y, and non of the M- ones work since that's for special characters. I understand they originally come from the readline library.

Now try C-k and then C-y

Then regular old Cmd + v.

You're welcome.

Well, cutting is called killing in Emacs...

So why is emodendroket referring to ctrl-w then?

In other words ctrl-w is "kill," which is what most people would think of as "cut," and ctrl-y is "yank," which is what most people would think of as "paste."

And Vimmers would think of yank as copy or kill save

That's funny. Never thought about that. I guess Emacs people think of it as yanking from the clipboard to the document, and Vim people think of it as yanking from the document into the clipboard.

I actually aliased :q to clear:


I also have clera, lcear, and lcera -> clear, and :tabe -> vim.

Are you aware Ctrl-l also clears? I can't recall the last time I typed clear.

I have to admit, I wince when I see someone type clear.

Not just `alias :q exit`?

Not really, if they mean `:q` to exit vim and go back to the terminal `alias :q=exit` wouldn't produce the desired result.

could really mess with it:

> alias :q=vim -c ':q'

best one

I really do that a lot so I aliased 'q' to exit in shell.

> Does anyone else actually do this besides OP.

Guilty as charged. I'll commonly start typing git, think about something else, switch to my editor, browser or an other terminal tab, then come back and type "git <command>" in full.


    > rg 'git =' ~/.gitconfig 
    7:	git = ! git

Something I have noted as part of my venturing into mechanical keyboards lead me to the revelation that many of my "mistakes" were really the keyboard failing me (ie, not properly register my keystrokes). All my life I assume was me the idiot that not know how use it. Only after I pay attention to how I use the keyboard (looking at my hands for a while) I start to see this.

So, I need to more firmly hit the keys in my actual driver (MS Ergo Keyboard) and now building my own mech...

P.D: ie: Maybe one of the different mech switches are more suited to the way YOU type:



P.D 2: This is a reply to all the ones that state that type wrong some commands.

Also, and maybe more common, is just bad typing. I was far worse before the use of the MS Ergo Keyboard (it DEMAND to use both hands.) So, if the performance change by keyboards (happend to me) maybe is a indication that are the tools at fault here..

This happens to me all the time on the new Macbook keyboard, especially with the arrow keys. I can watch myself press the key and see nothing happen. I really need to switch to a good external Mac keyboard.

I totally do this. I also occasionally will have something breaking and soon realize I typed 'git' randomly in the middle of a file instead of in my terminal...

I do stuff like because I alt-tab a lot and have so many similar-looking windows open. It's not just me either, I have seen stuff like "git pull" posted in chat rooms followed by "oops wrong window".

All the time, at least twice already today. Another common command that I'll start typing only to switch context from is vim.

Think about all the keystrokes you'd save if you just typed "vi" instead.

That's a habit I may never break. There's been enough times that vi was actually vi.

What kind of evil system ships with both vi and vim?

OpenBSD comes standard with vi. Vim is a package.

It ships nvi, as do the other BSDs. I think it's reasonable, BSDs have a stronger divide between the base system and third party packages, I'm not sure it would make a lot of sense to maintain vim as part of the former.

Besides on my FreeBSD system /usr/bin/vi is around 400kB while on my Debian machine /usr/bin/vim.basic is 2.4MB. It's not much these days but on embedded platform it could still make a significant difference.

Yep, and "nex/nvi are intended as bug-for-bug compatible replacements for the original Fourth Berkeley Software Distribution (4BSD) ex and vi programs."

Debian is the same way. But as soon as you open a file with vi on a fresh install, you know it isn't vim, so you close the editor, install vim, and then the vi command opens vim.

It's usually more "type git in a terminal then open a new tab to look something up and ALT-TAB back to the terminal" rather than a physical going away.

I type `ls ls something` a lot because of this.

As a related issue, it bothers me a lot when I type some command that I want to read the output, and then I proceed to run `ls` right in the sequence and move the output out of the screen.

... and then you clear the scrollback (Ctrl-L) but you can't just re-run the previous command because the system is now in a different state.

FWIW, I'm also baffled that this is a problem to solve.

Surprised how many are affirming this. Kind of a DAE moment. My fingers are a bit more tame from having spell check disabled & not falling back on these typo-aliases, as shown by the author's other aliases. Especially their t-prefix aliases which imply zsh aliasing gi to git

I sometimes do, though not specifically with git. Can be emacs, can be ls, can be anything where I interrupt my thought process.

So... I really fail to see why this article is of any relevance at all, really. Or at least a more global solution would have been better, but I think it's not really an annoyance. For me, it's the same as wanting to fix a UI so that I wouldn't re-double-click a software that I've already started (well, some prevent it, and generally when they do, it means there are sessions, and it annoys me).

I do the same with man instead (even though I only used that program like 50 times the last year) … it even happens in any other program where you can input text …

Yup. With lots of commands, not just git.

Leave the computer? No, never.

The author seems to have a lot of issues with spelling.

Everyone is different. I know an electrical engineer who grew up with dyslexia. So everyone finds their own solutions.

Personally I very rarely spell things wrong in cli.

It happens to me when cloning a repo. Sometimes I just write git clone ..., go to browser and the command already contains git clone, then i end up having sth like git clone git clone ...

I do. Everyone has their own tics; one of mine is that.

I do it all the time, but never thought it was the problem. Most often its to look up a reference number for a commit,

Then I get distracted on HN ...

No. I have aliases for most things git:

gs = git status

ga = git add

gc = git commit

gp = git push

gl = git pull

gt = git tag

I never started with those two-letter aliases because they're bound to become problematic:

- gs is ghostscript

- gc is a component of graphviz

...and all of a sudden your text editor can't generate PDFs anymore when started from the shell.

Instead, I use four-letter aliases which work fine:

- gits = git status

- gitd = git diff

- gitc = git commit


I aliased 'g' to 'git'. Combined with git aliases ('st' for 'status' etc) this is almost as short but doesn't steal all the short names from your shell. So instead of 'gs' you have 'g st'. Upside is you save two letters even on uncommon git commands :)

I do not. I thought the only reason that this was on the front page was because it was funny.

+1, what are you all looking at when typing git over and over again?

I just type git (or more commonly ls/cd) once on auto pilot because I'm at a terminal then without thinking about it hard I'll type it in consciously because that's why I'm at a terminal. It doesn't even involve looking away

Yep. And I did the exact same thing the OP did about it.

Yes, I do this all the time with all sorts of commands.

Sometimes, while copy pasting.

Often, yes.

I do it fairly often.

Yup, I do.

I want a terminal that highlights things it thinks are off. Like when I type cd cd or git git. But I don't want it to auto fix nor wait until the command is issued to complain.

This is because I want to be the sole controller of what command is actually issued. Call me an old curmudgeon but I just don't trust the auto fix solutions.

Edit: had no idea about Fish. Thank you, all.

Fish shell like syntax highlighting for zsh: https://github.com/zsh-users/zsh-syntax-highlighting

Fish-like autosuggestions for zsh: https://github.com/zsh-users/zsh-autosuggestions

Or if you don´t care for fiddling about too much and just want it to work out of the box: http://ohmyz.sh/

That's kinda what fish -- the friendly interactive shell - does, but more towards tab autocompletion than error detection.

Fish does this for missing files (though not invalid subcommands): https://fishshell.com/

Hey, don't forget about zsh with a highlighting plugin! :)

I'm using this without problems, and it's so comfortable to see the red highlighting when you mistyped: https://github.com/zdharma/fast-syntax-highlighting

That's actually EXACTLY what I had in mind. The fast version is so much better! :)

Why type out `git status`? I use `gst`, and lots of other great aliases provided by the [oh-my-zsh git plugin](https://github.com/robbyrussell/oh-my-zsh/blob/master/plugin...)

Somewhat related, from my .bashrc

  for a in $(git var -l | sed -nE 's/^alias\.([^=]*)=.*/\1/p') ; do
      if ! command -v g$a >/dev/null 2>&1 ; then
          alias g$a="git $a"
Which creates a shell alias prefixed with `g` for each of my configured git aliases if there is no conflict. So I get not only the `gst` command you mentioned and ones like `gco` (because I have Subversion-equivalent aliases for common commands), but more complex ones like `gstpup` (stash, pull upstream, stash pop). Combined with `alias g=git`, I seldom type "git" and the setup is pretty convenient. I've thought of making the above alias unconditionally, or report conflicts, as it can be jarring when an alias is missing. I've also considered expanding it to all git commands because sometimes my custom ones live as `git-$command` scripts and not aliases.

great thx

For me, it's because `gst` will only work on my machine. I like feeling at home on any system, so I'm loathe to depend heavily on aliases and configuration. One of the things I like about git git is that it appears to improve my experience without significantly affecting my habits.

How often are you running those commands elsewhere?

I used to do that, but I found it wasn’t actually saving me any cognitive load.

My newer philosophy toward git aliases is the one described here: http://gggritso.com/human-git-aliases. After reading this I totally overhauled my .gitconfig and replaced it with the one described here and I’m a lot happier.

I don't use either one anymore. I've switched to magit, which is faster than both and can also give you interactive menus and reminders of commands if you want.

I realized this myself. And eventually ended up with a fuzzy search thing (using FZF): https://github.com/chrissound/LinuxVerboseCommandLib

I can usually get away with typing the first letter of each word. So `gd` for git diff.

I've a variety of shell functions/aliases, like "gits" -> "git status -uno", gitd -> git diff, gitds -> git diff --staged, and so on.

I also have a variety of git aliases like:

        ## git log aliases
        # p  -> --patch
        # o  -> --oneline
        # r  -> --reverse
        # s  -> --stat
        # 1  -> -n1
        # m  -> master..
        # om -> origin/master..
        dom     = diff origin/master..
        doom    = diff origin/master..
        rbiom   = rebase -i origin/master
        lp      = log -p
        lo      = log --oneline
        lo1     = log --oneline -n1
        lr      = log --reverse
        lm      = log master..
        lrm     = log --reverse master..
        lor     = log --oneline --reverse
        lorm    = log --oneline --reverse master..
        lorom   = log --oneline --reverse origin/master..
        lom     = log --oneline master..
        loom    = log --oneline origin/master..
        l1      = log -n1

Why type 'gst'? I use C-x g, which is bound to magit-status:-)

Somewhat more seriously, I haven't had to worry about typing 'git git' because I haven't typed 'git' on a daily basis in years. I think I've probably typed it once in the last month.

The zsh git plugin, and scm_breeze (https://github.com/scmbreeze/scm_breeze), are two of my favorite nice-to-haves for improving the Git experience.

I have alias wow='git status' in my .profile because it's more fun (to me).

The mathematical term for a function that is the same when applied multiple times giving you the same results is called "idempotent" which translates to "same power". f^n(x)=f(x) for some positive natural number n and any x.


I had a senior dev interview with a major company in SV last year where the lead and hiring manager claimed that the description for this behavior was "side-effect free".

I didn't want to ruin my chances by correcting him that side-effects and idempotence refer to different qualities.

I passed the interview, but I've never forgotten that. The guy also seemed to have washed into the interview off his surf board.

Oh well. It was a very major company, so I let it all go.

In the context of software it seems like the word has pretty broadly adopted the meaning of "side-effect free". It's even made it to Wikipedia: https://en.wikipedia.org/wiki/Idempotence#Computer_science_m...

One notable example: Stripe's "idempotency keys": https://stripe.com/blog/idempotency

I understand 'idempotent' not as 'having no side effects' but as 'having the same side effects whether performed one or many times'. This is side-effect free:

  echo hello
This is side-effectful, but idempotent:

  echo hello >world
This is side-effectful and not idempotent:

  echo hello >>world

Mathematical idempotency depends heavily on the function's domain. It's not too challenging to construct a non-idempotent function that has an idempotent restriction. So depending on what your domain of interest some operations may be idempotent or not.

In the hello world example, I guess we are considering 'echo' as the function. If then if we consider stdout and echo's args to be the same, echo will be idempotent.

However, stdout and command args are pretty different things on any system I know. If we care about things like command line history, then clearly 'echo hello world' is not idempotent.

I disagree that your ‘ echo hello’ example is free of side effects. It writes to stdout. It overwrites $?. It changes the value of the last executed history command. Etc.

About the only side effect free operation at a blank line terminal prompt is _probably_ hitting enter or ctrl c. Or ‘#something<Enter>’

But your idempotency examples are spot on.

Basically, idempotency is a very useful concept. Side effect free isn’t.

> I disagree that your ‘ echo hello’ example is free of side effects.

I posit that you understand perfectly well what i was getting at! If it helps, imagine that you are spawning a fresh shell to execute each command line, through system(3) or some such.

Fair enough!

Interestingly, in this case the non-idempotent option is less safe.

Non-idempotent options are always unsafe; safe operations are a subset of idempotent operations.

(I suspect you meant “safe” in a different sense, but I couldn't resist.)

> safe operations are a subset of idempotent operations

Definitely not. 'Safe' means too many things in different contexts to make sweeping statements like that.

Here's one i came across recently. You are interacting with a stock exchange. You have sent an order to buy 100 shares of Twitter stock at some price, and it is now resting on the order book, waiting for orders to sell at that price. You see that the character limit on tweets is being increased, and decide that you don't want to buy 100 shares, but only 90, so you send a message to modify your order. At the same time, two other people, who have also seen the news, decide to dump their holdings of 90 shares each by sending sell orders at the price you are bidding. Their messages arrive just before and after yours. What happens?

If the message to reduce your order is a nasty non-idempotent one which says "reduce my order by 10", then:

1. First seller's order to sell 90 matches your order to buy 100; you buy 90, and your order is reduced to one to buy 10

2. Your modify message reduces your order of 10 to 0

3. Second seller's order to sell 90 arrives, but has nothing to match with

You have successfully bought 90 shares, well done.

If the message to reduce your order is a nice safe idempotent one which says "change my order to 90", then:

1. First seller's order to sell 90 matches your order to buy 100; you buy 90, and your order is reduced to one to buy 10

2. Your modify message increases your order of 10 to 90

3. Second seller's order to sell 90 matches your order to buy 90; you buy 90, and your order is reduced to 0

You have bought 180 shares. Oh dear.

This is not hypothetical. More than one new exchange has launched with a protocol where orders are modified to a target amount, rather than by a target delta, and changed it some time later, after their users got themselves in a pickle.

You can do a bit better by making the modify message a compare-and-set, so it only changes the quantity to 90 if it is currently 100. In that situation, the modify will fail, and the second order will sell you 10 shares. That's still not as good as the non-idempotent message.

> (I suspect you meant “safe” in a different sense, but I couldn't resist.)

The moral of this story is that computer scientists should not be allowed to use the word "safe"!

> > safe operations are a subset of idempotent operations

> Definitely not. 'Safe' means too many things in different contexts to make sweeping statements like that.

The intended reference (which I hoped would be recognized generally in this audience) was to he definition of “safe” and “idempotent” in HTTP (see section 4.2 of RFC 7231.)

(In your example, neither operation is “safe” in the HTTP sense; all state-modifying operations are unsafe.)

I agree with you generally that talking about 'safe' may be misleading. However, I don't think your example shows that idempotent operations can be 'unsafe' - I think it shows that the translation of user's intent to a system operation was lossy. The user's intent was to "buy a total of 90". Translating that to "Set my current order to 90", regardless of the idempotency of the operation, is not accurate, for precisely the reasons you stated. Neither is "reduce my order by 10", because the user may attempt to send the message "set my current order to 90/reduce my order by 10" multiple times(just to make sure it went through), and then they would get to buy less than 90 shares.

It would take different data structures and a different API to translate the user's intent correctly, and then the idempotence of the operation may be important. For example, if the order had a "total" and "current balance", you could be sending a message to set the total to 90(which would internally reduce the current balance), and since that message is idempotent, it's safe to send it multiple times.

> That's still not as good as the non-idempotent message.

Only if you can be sure the non-idempotent message arrived. It's not safe to re-send the delta message.

I disagree that this is common the world of software, and I disagree that the WP article that you linked makes that claim. I humbly suggest that you might benefit from reading that article more carefully.

You're right, I meant to summarize more along the lines that calling something multiple times doesn't cause more than one set of side effects. Unfortunately too late to edit by the time I re-read it!

It’s funny because if you read what they wrote, they’re fully aware of the difference between the two (since they reference the HTTP RFC definition of the idempotency of PUT and DELETE).

That difference is somewhat subtle and I had to read the description in the sibling comment to understand it. I would have welcomed a correction from somone I was interviewing.

On a side note, the founders of Google once tried to explain recursion and idempotence to Terry Gross on NPR. It's pretty amusing. It starts at 13:45 into the interview here:


You may have just been victim to the "let's see if they take a risk and correct me on my BS" test some interviewers give. Or they just didn't get it, that happens too. Some won't admit they're wrong even in the face of a mathematical proof..

I wonder what would have happened if you gave a short counter example.

You can also just use 'fuck' for this:

  > git git pull
  git: 'git' is not a git command. See 'git --help'.

  The most similar command is

  > fuck
  git pull [enter/↑/↓/ctrl+c]

Author missed an opportunity to title this "Git git Git git git git Git git."


Quite often, I accidentally press the space bar eagerly when typing git commands:

    $ gi tstatus
To fix this, I've added the following to my .bashrc:

    gi() {
        git "${args[@]}"
It also works if you drop the "t" altogether.

Ha! I have almost the same thing:

gi() { ARG=$(echo $1 | sed s/^t//); shift; git "$ARG" "$@"; }

> git config --global alias.git '!exec git'

Is the exec really required?

   git config --global alias.git '!git'
Will also work. Am I missing something?

EDIT: From git doc, "If the alias expansion is prefixed with an exclamation point, it will be treated as a shell command"

So exec is not required then.

You are right, I checked and the resulting sub-process tree is the same regardless of whether !git or !exec git is used.

Also, I found one caveat from the same docs:

> Note that shell commands will be executed from the top-level directory of a repository, which may not necessarily be the current directory. GIT_PREFIX is set as returned by running git rev-parse --show-prefix from the original current directory.

So, if I have a modified file `bar` in subdirectory `foo` under project root, and I am currently in `foo`, git status will show:

    modified:   bar
but git git status will show:

    modified:   foo/bar
To fix this, we should use cd first:

    git config --global alias.git '!cd "$GIT_PREFIX" && git'

I don't think you are missing anything, good catch.

erm, "git git foo"; in most shells can be fixed with "!*" as your next command. Repeat until lameness subsides.

Seriously though, I don't understand why people want to hide obvious errors like this - I'd much rather have the tool fail to execute than potentially perform some action I wasn't expecting.

Exactly. If anything I appreciate when errors are _highlighted_ a la `sl` (Steam locomotive) for `ls` or the `gti` for `git` that has a golf gti run across the screen

I never had the problem mentioned in the article, but for misspelled commands I trust git autocorrect:

git config --global help.autocorrect 1

It will run the correct misspelled command after 100ms. For example git stauts will be corrected automatically to git status http://schacon.github.io/git/git-config.html

I tend to type Ctrl-C then a command. Ctrl-C clears the line for you, so you can be sure that you are starting on a fresh line.

While the cleverness is admirable, there comes a point in your life when you realize you really do always want your own errors to fail loudly and immediately.

That is true given automatic error correction can backfire, I don't see how git git -> git autocorrect can backfire.

The backfires you can see ahead of time are never the problem, are they? :)

Sudo should stop working if your error rate rises to unusual high

Here are a number of great aliases that people might find helpful:


`!exec git` caused my shell to exit. I have a lot of stuff wrapping git in my shell though (including a bash function wrapping git itself!). The author himself only pushed up the change to his own gitconfig a few hours ago. It was previously `!$SHELL -c \"git $*\"`.

My version that works for my setup is `"!f() { git \"$@\"; }; f"`.

Hope this helps anyone who ran into the same issue, although I'm not 100% confident about the quoting.

EDIT: fixed the quoting, as per cryptonector's suggestion

EDIT2: need to quote the quotes for gitconfig to use it correctly

Add double quotes around $@.

Well... If you have this problem (I really don't), then you probably have it with more than just git, and the proposed workaround would be "a local solution to a global problem".

Reminds me of this Python line:

    decorator = decorator(decorator)(decorator)

There was a subtle bug when leaving out the last (decorator). I know, it's very silly.

I have homegrown aliases like 'tags' 'rdel' (git push origin --delete) 'ldel' (git branch --delete) and many more combined with Zsh's (Oh my Zsh)'s several aliases (e.g ggpull, glog, gp, gc) etc.

I also find "thefuck" is interesting but I love to control my fate :) (https://github.com/nvbn/thefuck)

Why type the singular, "git", so many times? We all know that you mean the plural "gits"!

   alias gits='git status'

This post would have been a lot better if he showed how to do a git subcommand that launched itself, which is where i thought he was going.

This isn't too hard. Aliases can expand to arbitrary shell commands, as shown in the article. So you can do something like:

    git config --global alias.bomb '!git bomb & git bomb'
to make a fork bomb.

This reminds me of something I read long ago that was along the lines of "make the computer change for you, don't change for the computer". As such, I have a small list of common typo's that I make that alias themselves to their correct forms.

Since then, I've found that these aliases have been the best workflow improvement I've ever made.

This is nice specifically because of the way the author uses `exec`. Without meaning to be patronizing, there must be lots of people reading the thread who don't know what `exec` does, and why it's a neat solution to this problem (or non-problem, whatever your view is); I'd say do look it up if you're interested in programming.

Author here, I'm glad someone else appreciated it besides me. :-)

(It's especially pleasing to watch the system calls it generates via strace or dtrace!)

After setting this alias in .gitconfig, I tried `git git log`

Works fine, but when I press quit (q), it says `error: exec git died of signal 13`

As I was reading the article, I heard "git git git git" in the glitch audio form in my head... anyone?

I heard Desiigner.. completed the title in my head with "I got broads in Atlanta"

I can't hear that one without thinking of this :D


"But I don't wanna commit"

I sometimes have this problem but I hate solutions like this because I figure if I make this kind of mistake, I'm not paying sufficient enough attention to what I'm doing at the moment.

I take a minute, clear out distractions and then come back to what I'm working on.

Great for C programmers. Goes with:

  printf("Hello, world!\n");
  (printf)("Hello, world!\n");
  (*printf)("Hello, world!\n");
  (**printf)("Hello, world!\n");
  (***printf)("Hello, world!\n");

The danger of this is if you accidentally write 'git git something' into a shell script and it works on your machine, then you commit the script to a repo and it doesn't work for anyone else.

I suppose this is a problem with any alias.

One way around that issue is to prefix commands you intend to share with backslash:

    $ \gstatus
    gstatus: command not found

    $ gstatus
    git status stuff
The backslash just disables alias expansion. This works on all shells I'm aware of. It won't help with other portability concerns like actual missing commands though, of course.

I find writing shell scripts is a different mental process than interacting with the commandline, so I think the problem of “starting a command then leaving the terminal” is non-existant in that context.

It would be cool if you could generalize this for anything (e.g. ls ls -al). That being said, I wonder if there's any actual command-line utilities that actually use a similar syntax to perform something useful.

great minds think alike? I've had this exact system for a long time: https://github.com/jes5199/git-git

There is a GitHub repository full of neat tricks like this: https://github.com/GitAlias/gitalias

I often type "git stats" but I've never felt the need to go through all of this just because I'm lazy. Then again maybe that's an ironic example of laziness.

Why type "git" and walk away? Seems like an ultra edge case that deserves whatever ill comes from it.

Does anyone else do `qgit`? `q` to quit the pager, but the output of the previous command unexpectedly fit on one screen.

I thought everyone used shortcuts for git. e.g.: `gs` means `git status` or `gpom` means `git pull origin master` etc

C-w would have solved that problem quickly :)

Why is this a problem? Is the author blind? If this happens with git then surely it happens with every command. What about "rm"? What if I type "rm -Rf", leave, then come back and type something else? Maybe a better solution is to change behaviour, or if there really is some reason for this behaviour, have something delete the currently entered command after it's been idle for some seconds.

I think it was meant as light hearted humor.

I find this much simpler: ln -s $(which git) [some dir in your $PATH]/git-git

No, no I have not ever had too many gits...

(is this really a thing?)

apt-get install sl

Also `alias gti="echo 'vroom vroom'"`

yeah it's nice, git git happens! I have a lot of this shortcuts for git, zsh and especially for vim (:Q, :Qall, :QALL etc...)

Nearly as good as

alias gti=git

Don't forget "igt".

Off-topic, but this site is pretty.

typing that means you probably needs some rest to let your brain refuel imo.

also, I had to add alias got='git' in my bashrc. Typo galore.

how about looking at what you type instead of the keyboard?

you can also just get away with git = !"git"

At first alias g=git

This is a manager problem, right?

This is a joke, right? It has to be a joke.

At first I thought this title was pointing to the quirky symptom of Clojure's default value for the "get" function that allows this statement:

(get get get get)

to be equivalent to this one:


as in:

((get get get get) {:a 1} :a)

I was very excited about an article on this topic.

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