0

I am using Gitea and currently trying to use the command line to checkout a single file using this

git archive --remote=git://gitea.server.com/project.git HEAD:path/to/directory filename | tar -x

from Retrieve a single file from a repository

But I am not able to include the credentials in order to work.

I have tried two combinations with my username and its generated access token

--remote=git://username:token@gitea.server.com/project.git

--remote=username:token@gitea.server.com/project.git

But it never works.

How can I include the user credentials in order to checkout a single file in one line?

Shadow
  • 4,168
  • 5
  • 41
  • 72

1 Answers1

1

git:// refers to the git protocol (typically found on port 9418). This protocol is unauthenticated: it has no capability to provide a user name, much less any security information about that user name. If you have a server that serves such a port, every file in every repository served by this server is completely open to everyone. There's no need for a user name and token, and you wouldn't provide one.

The syntax username:token@host.name/path/to/repo.git is shorthand for ssh://username:token@host.name/path/to/repo.git and hence uses the ssh protocol. Ssh doesn't take passwords or tokens here so username:token is the whole user name. (Colons are allowed after the @ and specify the ssh port, in place of the default 22.)

To use https, which is where you would use a user name and token, use https://username:token@host.name/path/to.repo.git. The https:// part is not optional.

torek
  • 448,244
  • 59
  • 642
  • 775
  • This worked to a certain degree in the sense that it is the solution to my problem. My other problem is my gitea apparently is not compatible with `git archive` since it throws back `fatal: operation not supported by protocol` but that is outside the scope of this question. – Shadow Oct 12 '22 at 13:27
  • That particular error seems odd, but I've never set up a Gitea server so I don't know where to start looking for that. – torek Oct 12 '22 at 18:56