The steps described in this post were done using IntelliJ IDEA CE 2019.3 and macOS High Sierra (10.13.6).
When setting up GitHub in IntelliJ we have to follow some tricky steps.
I'll show the ones that I have passed by.
The first step is to configure the GitHub account.
To do that, just click in Configure link on IntelliJ Welcome Screen and then in Preferences option.
Open Version Control section and then GitHub.
Click in the + button and add the credentials.
If you want to use SSH (by the way, that is recommended for security reasons), you should tick "Clone git repositories using ssh" and click OK.
But...
(Here comes the first trick)
If you don't have added the SSH key for your computer on the GitHub website, you'll not be able to use this option.
Let's see how to add it then:
- Open the Terminal app
-
Enter the following line:
ssh-keygen -t rsa
Press ENTER key to accept the default location to save the files
Create a password for your keys (you'll need to type it twice)
Your keys are now saved in .ssh folder inside your home folder.-
To copy it, use the command below:
pbcopy < ~/.ssh/id_rsa.pub
Now, access the GitHub website, click in your avatar picture (top-right) and then Settings option.
Click in SSH and GPG key then in the green button named New SSH key.
Type a name that identifies your computer, pastes the key and finish by clicking in the Add SSH key button.
With the SSH key added to the GitHub website, you can now clone a repository by using the Get from Version Control option in Welcome to IntelliJ IDEA screen.
Now that your repository was copied locally, you can commit using VCS>Commit (⌘ + K) option on the menu and push by using VCS>Git>Push (⌘ + ⇧ + K).
And here comes another trick.
For security reasons, GitHub has two options in Email settings that helps protect your privacy (Keep my email addresses private and Block command line pushes that expose my email).
If those options are ticked, maybe you receive an error when you try to push your commits.
Unfortunately, the error notification doesn't always have enough information.
Using the menu View>Tool Windows>Version Control (⌘ + 9), you can see more detailed information at the Log tab.
You should probably see the below message:
Your push would publish a private email address.
So, how can I push my commits while keeping my privacy?
GitHub provides us an email to avoid exposes our private email.
Let's see the steps to get it and solve the issue:
- Access your GitHub Settings>E-mail and you will see the provided email at the first line of the Keep my email addresses private section (highlighted in the image above)
- Copy it to the clipboard
- Open the Terminal app
- Navigate to your local repository directory
-
Type the text below (replacing the content between the quotation marks with your email copied in step 2):
git config --global user.email "{ID}+{username}@users.noreply.github.com"
-
Reset the author information:
git commit --amend --reset-author
Return to IntelliJ and now you can push by pressing ⌘ + ⇧ + K
Congratulations.
Now you've finished the IntelliJ/GitHub setup and can start to code.
Happy coding!
Victor Macarios
Sources:
https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh
Top comments (0)