Verify the Git Credentials supplied by the User

Viewed 380

I am writing an application in which we will support git integration. The user will provide us with his git credentials so that we can push some files on his git.

The git credentials which user will supply can be

  1. The Account URL, eg: https://github.com/OpenPrinting
  2. HTTP (Username and Password/ Kerberos)
  3. SSH

Before saving the user credentials I want to validate that the credentials entered is valid.

The user might be using GithHub/BitBucket/GitLab. I am trying to find some git command or some frameworks in java which I can use to validate the credentials. Can you please point me to some command/logic which I can try?

What I have tried ? I tried git ls-remote command, but it requires the repo name/url. In one of our use case, the user won't specify the repository name or URL beforehand. Because of which I am not able to use this command.

1 Answers

I tried git ls-remote command, but it requires the repo name/url. In one of our use case, the user won't specify the repository name beforehand. Because of which I am not able to use this command.

You must at least have the URL to test the credentials.

git ls-remote will take a URL. Use -h to limit the output.

git ls-remote -h <url>

All you need to check is the exit code.

Related