Home > Software design >  Checkout a single file with credentials in one line in cmd
Checkout a single file with credentials in one line in cmd

Time:10-13

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:[email protected]/project.git

--remote=username:[email protected]/project.git

But it never works.

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

CodePudding user response:

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:[email protected]/path/to/repo.git is shorthand for ssh://username:[email protected]/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:[email protected]/path/to.repo.git. The https:// part is not optional.

  • Related