Search code examples
gitgit-shell

Which default commands work in git-shell?


I log into git-shell with PuTTy using a password. Whatever I type into the git-shell (the restricted login shell on a Debian linux server) results in a response like "unrecognized command".

git> git help -a
unrecognized command 'git'

Solution

  • git-shell is, by design, very limited. See the man page for more details.

    By default, it can only run a few commands, to allow for push/pull actions. This is a way for git servers to offer "safe" SSH access that is limited to only interacting with git repositories. Also by default, there is no interactive login access.

    Note that simply to do push/pull/fetch operations using git-shell, you do not need to do anything special. It can already do those things. You only need to define custom commands if you want to do something unusual.

    You say in comments that you have a ~/git-shell-commands/ directory, but it is empty. The presence of the directory will enable interactive mode, so you are getting a git> prompt. However, that the commands directory is empty means there are no valid commands you can run. In this scenario, the only thing you can run is exit to leave the shell.

    To use git-shell, you will need to create some commands in ~/git-shell-commands. What exactly to create is up to you. An example might be to create list, and have that script return a list of the available repositories on the server.

    If you want to use "standard commands," as you indicate in the comments, then I think the answer is that git-shell is not the tool you are looking for. It sounds like you are looking for a regular login shell.

    An example custom command might look like this. Here's an implementation of the list command I suggested above.

    #!/bin/bash
    
    # Assuming all repositories are named `*.git`
    for repo in $(ls -d *.git); do
    
        # Just in case one exists, ignore ".git"
        if [[ "$repo" != ".git" ]];
            # Trim off the extension
            echo $(basename $repo .git)
        fi
    
    done
    

    There are a couple of examples in this blog post.