Using Git Client with IntelliJ IDEA

Installation

You will first need the Git Client installing before you can configure IntelliJ IDEA to use Git.

Repository access

For illustrative purposes, company's GitHub Enterprise instance is used in the following instructions as this is likely to be the common use case.

Other repositories should be usable, but exact steps may differ slightly.

Token generation

You need to generate a Personal access token for the repository you are connecting to. This can be done via your Profile > Edit profile page or directly from https://alm-github.systems.uk.company/settings/tokens.

This approach is preferable to using your repository username/password in IntelliJ IDEA as you won''t have to update it when your password changes.

Select Generate new token, give your token a description and select the required scopes (defaults should be fine for in most cases) and select Generate token.

Copy the generated token to your clipboard or, temporarily, to a file. You should not save this token permanently or pass it to anyone else as it will allow access to your repositories using your account.

Configuration

Because of the way IntelliJ IDEA works in conjunction with Git, you need to configure both the Git Client and IntelliJ IDEA to use the generated token. This is because IntelliJ IDEA delegates some actions to the command line instance.

Git Client

Two approaches to configuring the Git Client so that it does not need to continually authenticate are listed below.

  • The store mode saves the credentials to a plain-text file on disk, and they never expire. This means that until you change your password for the Git host, you won’t ever have to type in your credentials again. The downside is that they are stored in your home directory in cleartext, e.g. Z:.git-credentials.
  • The wincred approach can only be used on Windows and uses the Windows Credential Store to control sensitive information.

To configure the Git Client to automatically authenticate, type the following at a command line:

git config --global credential.helper store

or

git config --global credential.helper wincred 

then

git ls-remote https://<generated token>:x-oauth-basic@alm-github.systems.uk.company/path/to/repository.git 

The first command tells Git to locally store any credentials entered as a result of any following Git commands.

The second command just lists the references in the repository using the generated token for authentication. this allows Git to store the token for future use. Just replace with your actual token and path/to/repository.git to a repository you have access to.

IntelliJ IDEA configuration

Open the GitHub Settings dialogue, File -> Settings -> Version Control -> Github and set the following fields:
•Host: alm-github.systems.uk.company
•Auth Type: Token
•Token: paste in your generated token

You can then select Test to check that your access is working.

Conclusion

You should now be good to go to access your GitHub repositories from the command line or IntelliJ IDEA without having to authenticate.

Reference

Show Comments