16 ms·
Git git git git git
- kobeya 9y agoThis 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.
- ekimekim 9y agoThis 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.
- Waterluvian 9y agoI 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.
- erichdongubler 9y agoHey, don't forget about zsh with a highlighting plugin! :)
- fdw 9y agoI'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 https://github.com/zdharma/fast-syntax-highlighting
- erichdongubler 9y agoThat's actually EXACTLY what I had in mind. The fast version is so much better! :)
- phillco 9y agoFish does this for missing files (though not invalid subcommands): https://fishshell.com/ https://fishshell.com/
- jldugger 9y agoThat's kinda what fish -- the friendly interactive shell - does, but more towards tab autocompletion than error detection.
- nlo 9y agoFish shell like syntax highlighting for zsh: https://github.com/zsh-users/zsh-syntax-highlighting https://github.com/zsh-users/zsh-syntax-highlighting Fish-like autosuggestions for zsh: https://github.com/zsh-users/zsh-autosuggestions https://github.com/zsh-users/zsh-autosuggestions
- Vinkekatten 9y agoOr if you don´t care for fiddling about too much and just want it to work out of the box: http://ohmyz.sh/ http://ohmyz.sh/
- bowmessage 9y agoWhy 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/plugins/git/git.plugin.zsh https://github.com/robbyrussell/oh-my-zsh/blob/master/plugin...)
- Analemma_ 9y agoI 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 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.
- pmoriarty 9y agoI 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.
- chrissoundz 9y agoI realized this myself. And eventually ended up with a fuzzy search thing (using FZF): https://github.com/chrissound/LinuxVerboseCommandLib https://github.com/chrissound/LinuxVerboseCommandLib I can usually get away with typing the first letter of each word. So `gd` for git diff.
- oinksoft 9y agoSomewhat 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" fi done 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.
- jrimbault 9y agoC-w would have solved that problem quickly :)
- hellofunk 9y agoAt 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: get as in: ((get get get get) {:a 1} :a) I was very excited about an article on this topic.
- notthemessiah 9y agoThe 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. https://en.wikipedia.org/wiki/Idempotence https://en.wikipedia.org/wiki/Idempotence
- hellofunk 9y agoI 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.
- Jach 9y agoYou 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..
- dylanpyle 9y agoIn 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_meaning https://en.wikipedia.org/wiki/Idempotence#Computer_science_m... One notable example: Stripe's "idempotency keys": https://stripe.com/blog/idempotency https://stripe.com/blog/idempotency
- twic 9y agoI 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
- gulperxcx 9y ago>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.
- michael_storm 9y agoI do. Everyone has their own tics; one of mine is that.
- oneeyedpigeon 9y agoYup. With lots of commands, not just git.
- kellyjprice 9y agoAll the time, at least twice already today. Another common command that I'll start typing only to switch context from is vim.
- smellf 9y agoThink about all the keystrokes you'd save if you just typed "vi" instead.
- kellyjprice 9y agoThat's a habit I may never break. There's been enough times that vi was actually vi.
- empath75 9y agoYou 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 init > fuck git pull [enter/↑/↓/ctrl+c]
- web007 9y agoAKA https://github.com/nvbn/thefuck https://github.com/nvbn/thefuck
- Breakthrough 9y agoIt 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.
- steventhedev 9y ago`!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
- cryptonector 9y agoAdd double quotes around $@.
- 4ad 9y agoThis is a joke, right? It has to be a joke.
- deleted 9y ago[deleted]
- deleted 9y ago[deleted]
- negativ0 9y agoyeah it's nice, git git happens! I have a lot of this shortcuts for git, zsh and especially for vim (:Q, :Qall, :QALL etc...)
- z3t4 9y agoSudo should stop working if your error rate rises to unusual high
- rurban 9y agoAt first alias g=git
- sgloutnikov 9y agoHere are a number of great aliases that people might find helpful: http://durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/ http://durdn.com/blog/2012/11/22/must-have-git-aliases-advan...
- IgorPartola 9y agoapt-get install sl
- IgorPartola 9y agoAlso `alias gti="echo 'vroom vroom'"`
- alexchamberlain 9y agoThis is a manager problem, right?
- salgernon 9y agoerm, "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.
- shawncplus 9y agoExactly. 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
- js2 9y agoAuthor missed an opportunity to title this "Git git Git git git git Git git." https://en.wikipedia.org/wiki/Buffalo_buffalo_Buffalo_buffalo_buffalo_buffalo_Buffalo_buffalo https://en.wikipedia.org/wiki/Buffalo_buffalo_Buffalo_buffal...
- jes5199 9y agogreat minds think alike? I've had this exact system for a long time: https://github.com/jes5199/git-git https://github.com/jes5199/git-git
- metrognome 9y agoQuite 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() { args=("$@") args[0]=${args[0]/t/} git "${args[@]}" } It also works if you drop the "t" altogether.
- QuercusMax 9y agoHa! I have almost the same thing: gi() { ARG=$(echo $1 | sed s/^t//); shift; git "$ARG" "$@"; }
- Walkman 9y agoThere is a GitHub repository full of neat tricks like this: https://github.com/GitAlias/gitalias https://github.com/GitAlias/gitalias
- moogly 9y agoWell... 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".
- bandrami 9y agoWhile 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.
- mimo84 9y agoI 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 http://schacon.github.io/git/git-config.html
- kazinator 9y agoGreat 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");
- asveikau 9y agoThe 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.
- thisacctforreal 9y agoI 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.
- xelxebar 9y agoOne way around that issue is to prefix commands you intend to share with backslash: $ \gstatus gstatus: command not found vs $ 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.
- mbrumlow 9y agoNo, no I have not ever had too many gits... (is this really a thing?)
- shruubi 9y agoThis 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.
- Myrmornis 9y agoThis 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.
- caiusdurling 9y agoAuthor 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!)
- temporallobe 9y agoI 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.
- deleted 9y ago[deleted]
- abecedarius 9y agoReminds me of this Python line: decorator = decorator(decorator)(decorator) https://github.com/darius/sketchbook/blob/master/misc/decorator.py https://github.com/darius/sketchbook/blob/master/misc/decora... There was a subtle bug when leaving out the last (decorator). I know, it's very silly.
- shiven 9y agoWhy type the singular, "git", so many times? We all know that you mean the plural "gits"! alias gits='git status'
- deeteecee 9y agotyping that means you probably needs some rest to let your brain refuel imo.
- xelxebar 9y agoOff-topic, but this site is pretty.
- nu11p01n73R 9y ago> 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.
- sgillen 9y agoI don't think you are missing anything, good catch.
- vesinisa 9y agoYou 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'
- taejo 9y agoDoes anyone else do `qgit`? `q` to quit the pager, but the output of the previous command unexpectedly fit on one screen.
- itsashis4u 9y agoAfter 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`
- yeukhon 9y agoAs I was reading the article, I heard "git git git git" in the glitch audio form in my head... anyone?
- hupperz 9y agoI heard Desiigner.. completed the title in my head with "I got broads in Atlanta"
- gourou 9y ago"But I don't wanna commit"
- literallycancer 9y agoI can't hear that one without thinking of this :D https://soundcloud.com/joshpan/panda-desiigner-adlibs https://soundcloud.com/joshpan/panda-desiigner-adlibs
- isarat 9y agoI 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 https://github.com/nvbn/thefuck)
- cup-of-tea 9y agoWhy 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.
- olalonde 9y agoI think it was meant as light hearted humor.
- stereobit 9y agoNearly as good as alias gti=git
- Walf 9y agoDon't forget "igt".
- Keloran 9y agoyou can also just get away with git = !"git"
- alex_duf 9y agoalso, I had to add alias got='git' in my bashrc. Typo galore.
- tardo99 9y agoI thought everyone used shortcuts for git. e.g.: `gs` means `git status` or `gpom` means `git pull origin master` etc
- hackbinary 9y agoI 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.
- busterarm 9y agoI 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.
- lamflam 9y agoI find this much simpler: ln -s $(which git) [some dir in your $PATH]/git-git
- alkz 9y agohow about looking at what you type instead of the keyboard?
- bradezone 9y agoWhy type "git" and walk away? Seems like an ultra edge case that deserves whatever ill comes from it.