Is it possible to run git commands without the git prefix

As the name says, is it possible to run an interactive git shell where all commands are automatically prefixed with git ?

So instead:

 git fetch git add git commit 

I want to do something like this:

 git -i #start the 'interactive' git shell, not the right command obviously fetch #does git fetch add #does git add commit #does git commit git -x #exit the 'interactive' git shell 
+5
source share
3 answers

I do not think that such a mode is built into git. I suggest you check out git-sh . You can configure it to use the aliases you prefer.

+7
source

If you use a Bash shell, you can install a โ€œcommand not found handlerโ€, which is a shell function that will be run whenever a command is not recognized. You can use this to try running git-status if you run status and the shell cannot find this command, for example.

 command_not_found_handle() { gitcmd=`git --exec-path`/git-$1 ; if type -a $gitcmd >/dev/null 2>&1 ; then shift ; exec $gitcmd " $@ " ; fi ; echo "bash: $1: command not found" >&2 ; return 1 ; } 

This will not expand the git aliases, it only recognizes commands that exist as executables in the GIT_EXEC_PATH directory, for example /usr/libexec/git-core/git-status

 master*% src$ pwd /home/jwakely/src/foo/src master*% src$ git status -s M include/foo.h ?? TODO master*% src$ status -s # runs 'git-status -s' M include/foo.h ?? TODO master*% src$ git st # a git alias M include/foo.h ?? TODO master*% src$ st # does not recognize git alias bash: st: command not found 

If you want it to handle aliases, but with the disadvantage that any unrecognized command (including typos) will be passed to Git, you can make it a lot easier:

 command_not_found_handle() { git " $@ " ; } master*% src$ st # runs 'git st' M include/foo.h ?? TODO master*% src$ statu # runs 'git statu' git: 'statu' is not a git command. See 'git --help'. Did you mean one of these? status stage stash 
+2
source

gitsh is maybe what you are looking for.

http://robots.thoughtbot.com/announcing-gitsh

And the github repository: https://github.com/thoughtbot/gitsh

+1
source

Source: https://habr.com/ru/post/1200111/


All Articles