Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run git commands without git prefix

Tags:

git

linux

ubuntu

As the title says, is it possible to start an interactive git shell where all the commands are automatically prefixed by git?

So instead of doing:

git fetch
git add
git commit

I want to be able 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
like image 594
7331skillz Avatar asked Aug 12 '14 10:08

7331skillz


3 Answers

I don't think such a mode is in integrated in git. I suggest you to check git-sh. You can configure it to use the aliases you prefer.

like image 123
enrico.bacis Avatar answered Sep 27 '22 21:09

enrico.bacis


If you're using the Bash shell you can set a "command not found handler" which is a shell function that will be run whenever any command is not recognized. You can use that to try running git-status if you run status and the shell can't find that command e.g.

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 won't expand git aliases, it only recognizes the commands that exist as executables in the GIT_EXEC_PATH directory, such as /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 downside that any unrecognized command (including typos) will be passed to Git, you can make it much simpler:

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
like image 35
Jonathan Wakely Avatar answered Sep 27 '22 23:09

Jonathan Wakely


gitsh is, maybe, what are you looking for.

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

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

like image 40
djm.im Avatar answered Sep 27 '22 21:09

djm.im