sdaau
sdaau

Reputation: 38619

Run git commands on remote?

I have already seen:

Judging by this, for what I want to do, I have to login via ssh and run a script on the remote server; but I was hoping for a more git-integrated solution, so let me explain what I want to do.

I have a remote repo, which is git-svn; then I have a local git-only repo which is a clone of the remote. So, the local has a reference to the remote URL in remote.origin.url (seen via git config --list).

What I want to do, is run the equivalent of git svn log (maybe with some post-processing) on the remote, but with the call initiated from the local machine/repo - and get the results, again on the local machine/repo. Of course, git-svn may not even be installed on the local machine, which means only the remote would be able to understand such a command.

I'd be ready to code a hook for the remote repo - but as far as I can see, hooks can run only at specified events (i.e. pull, update...) - you cannot really call them arbitrarily: I remember, once I was developing a post-update script; and to debug it, I had to set it to return an error always, and then I'd "push" a "fake" commit, which would have run the script, and upon the reception of the error, roll-back the repo -- of course, this is not how I imagine the remote script should run.

Another thing that might be possible is to code an alias for the local repo, which then calls SSH in respect to the remote.origin.url - maybe that would make the running of git svn log remotely a bit easier?

In the end, this is my question - what options do I have to run a relatively custom git command (like git svn log, or a git alias defined remotely) on a remote repo, by utilizing to greatest extent possible the data already available in the local repo (that is, I want to avoid writing a bash script, with repeated hardcoded paths/URLs, that will call ssh and do whatever necessary on the remote) -- possibly, in a similar manner that a remote post-update git hook returns its stdout to the local caller, prefixed by "remote: "?

Upvotes: 8

Views: 7666

Answers (1)

Greg Hewgill
Greg Hewgill

Reputation: 993163

The answer here seems to be essentially:

ssh server 'cd /path/to/repo && git svn log'

You can write a little bit of code to get server and /path/to/repo from git remote (assuming your remote is an ssh type remote). No other context information should be necessary other than what can be easily found in the local git repo.

Upvotes: 2

Related Questions