Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run git commands on remote?

Tags:

git

git-remote

I have already seen:

  • How to run GIT commands on remote repository - "SSH into the server" or "git fetch; gitk --all"
  • Run git commands on remote working tree (GIT_WORK_TREE=/path) - the answer is about git push --tags
  • How to "git show" on a remote repo? - "Use git fetch to get the remote history, then snatch the file from the local object store."
  • How to run git command remotely? - "ssh username@host "cd my/repo/path && git show""
  • How can I manually run the hook post-receive on git? "A hook is an executable shell script. You can execute it from the command line if you need to run it by hand, although constructing the expected stdin inuput is somewhat tedious if your repo has more than one head (that is, you use branches)."
  • Detecting changes to remote branch - "Don't monitor files in the inner workings of git manually. Use git to check things for you. In this case git rev-parse --verify origin/master will show you the SHA of your local copy of origin/master, and git ls-remote origin master to get the SHA from the remote."
  • Commit history on remote repository - "git log remotename/branchname - You can't connect directly to the server to check the log there, what you do is download the state of the server with git fetch and then locally see the log of the remote branches."

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: "?

like image 730
sdaau Avatar asked Jul 21 '14 01:07

sdaau


People also ask

How do I run a git remote command?

How to run GIT commands on remote repository - "SSH into the server" or " git fetch ; gitk --all " Run git commands on remote working tree (GIT_WORK_TREE=/path) - the answer is about git push --tags.

Which git commands are not run locally but need to connect with remote repo?

When I talk to colleagues about Git, I tell them, that there are only three Git commands that cannot be executed without going to a remote repository once a local repo is initialized (assuming that origin is not on the local machine, of course): git fetch. git pull. git push.

What is remote in git bash?

The "remote" command helps you to manage connections to remote repositories. It allows you to show which remotes are currently connected, but also to add new connections or remove existing ones.


1 Answers

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.

like image 61
Greg Hewgill Avatar answered Oct 19 '22 00:10

Greg Hewgill