Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run git commands on remote without having local repo

I have a script called 'git-export' which helps me to export a remote repository. It is run like that:

git-export http://host.com/git-repo <-t tag or -b branch or -c commit> /local/dir

Before it was used to export local repository and I used these commands:

to get commit from branch:

git branch -v --no-abbrev|awk '($1=="'$BRANCH'") || ($1 == "*" && $2 == "'$BRANCH'"){if($1 == "*"){print $3;}else{print $2;}}'

or

git rev-parse -q --verify $BRANCH^{commit}

to get commit by tag:

git rev-parse -q --verify $TAG^{commit}

also I have scripts to list tags, versions (tags, starting with v), I use git branch -v to show branches....

Question is: How can I do these things on remote repository without having local. Is there some general way to query remote. For example: git --remote=http://host.com/repo branch -v or git --remote=http://host.com/repo log

Resion: If I want to install software on remote host I just want to

  1. list versions, branches, etc
  2. export specific version/branch/commit and show SHA1 of the commit regardless which one of these I export (by export I mean git archive --remote=<repo>|tar x)

edit:

I don't want to actionalyl run the commands on remote. I want to use the remote repository with local commands and display it formatted.

like image 428
NickSoft Avatar asked Apr 16 '11 12:04

NickSoft


People also ask

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.

Do you need a remote repository to use git?

You don't need to have a remote repository at all. You can have the full git experience, with commits, branches, merges, rebases, etc, with only a local repository. The purpose of a remote repository (eg, GitHub) is to publish your code to the world (or to some people) and allow them to read or write it.


1 Answers

You're looking for git ls-remote. For example:

$ git ls-remote git://git.kernel.org/pub/scm/git/git.git
4d8b32a2e1758236c4c1b714f179892e3bce982c    HEAD
f75a94048af9e423a3d8cba694531d0d08bd82b4    refs/heads/html
810cae53e0f622d6804f063c04a83dbc3a11b7ca    refs/heads/maint
70b5eebd65f2d47fd69073aed1d3da0f1fd7a017    refs/heads/man
4d8b32a2e1758236c4c1b714f179892e3bce982c    refs/heads/master
b9f1b13437fd0b8b1857ffbdebb9e1adc50481f0    refs/heads/next
83a9d3226b19a683a9a783bde0784c2caf19e9a1    refs/heads/pu
2309986900ed1a5744b3a81c507943593000ce32    refs/heads/todo
d5aef6e4d58cfe1549adef5b436f3ace984e8c86    refs/tags/gitgui-0.10.0
3d654be48f65545c4d3e35f5d3bbed5489820930    refs/tags/gitgui-0.10.0^{}
33682a5e98adfd8ba4ce0e21363c443bd273eb77    refs/tags/gitgui-0.10.1
729ffa50f75a025935623bfc58d0932c65f7de2f    refs/tags/gitgui-0.10.1^{}
...
(git.git has a lot of tags!)

You can limit yourself to branches with the --heads option or tags with the --tags option, or specify a pattern to select refs, for example to see only the git version tags from git.git, git ls-remote <url> refs/tags/v*. Or you might already know exactly what ref you want: git ls-remote <url> HEAD.

You can't run arbitrary commands on arbitrary remotes, though. The transfer protocols don't support that - they're designed to support listing refs and transferring objects (via packs). In particular, you won't be able to do anything analogous to rev-list. You'll be limited to getting SHA1s for commits pointed to by refs.

like image 123
Cascabel Avatar answered Oct 09 '22 18:10

Cascabel