IntelliJ IDEA 2018.1 Help

Manage projects hosted on GitHub

IntelliJ IDEA allows you to manage projects controlled by Git that are hosted on GitHub without leaving the IDE.

Commands used to manage GitHub projects from within IntelliJ IDEA are only available if you have a GitHub project specified as your project remote.

Register a GitHub account in IntelliJ IDEA

To retrieve data from a repository hosted on GitHub, and to be able to share your projects, you need to register your GitHub account in IntelliJ IDEA. You can also create an account on GitHub without leaving the IDE if you do not have one yet.

In either case, IntelliJ IDEA remembers your login and password, so you do not have to specify your credentials each time you retrieve data from a remote, or push your commits.

Register an existing GitHub account

If you enable two-factor authentication and you use SSH to access your repositories, you can choose any authentication type - password or token.

If you use the HTTPs protocol to access your remote repositories on GitHub, you need to configure an Access token and use it to authenticate, otherwise remote Git operations will fail. When prompted for credentials, either enter the token as your username and leave the password field empty, or specify the token instead of your password.

To register your account, do the following:

Invoke the Settings dialog (Ctrl+Alt+S) and select Version Control | GitHub in the left pane.

Select the type of authentication that you want to use from the Auth Type drop-down list:

Password. If this option is selected and you have two-factor authentication enabled in your GitHub account settings, you will be asked to enter an authentication code each time IntelliJ IDEA requires you to log in to your GitHub account.

Token (recommended by GitHub for authentication from third-party applications, as it does not require IntelliJ IDEA to remember your password).

Create a new GitHub account

Invoke the Settings dialog (Ctrl+Alt+S) and select Version Control | GitHub in the left pane.

Click the Sign up link.

On the Sign up for GitHub page that opens in the browser, choose the account plan (free or paid), and specify the requested information. When you are done creating an account, the GitHub Welcome Page is displayed.

Checkout a project from GitHub

IntelliJ IDEA allows you to check out (clone) a repository from GitHub and create a new project based on it:

From the main menu, choose VCS | Checkout from Version Control | Git.

In the Clone Repository dialog that opens, specify the URL of the repository that you want to clone, or select a repository from the list that contains all GitHub projects associated with your account and the organization that your account belongs to.

In the Directory field, specify the path where the folder for your local Git repository will be created into which the remote repository will be cloned.

Click Clone. If you want to create a IntelliJ IDEA project based on the sources you have cloned, click Yes in the confirmation dialog. Git root mapping will be automatically set to the project root directory.

Share a project on GitHub

If you want to add a remote repository for your project on GitHub, do the following:

Open the project you want to share.

From the main menu, choose VCS | Import into Version Control | Share Project on GitHub.

If you have not registered your GitHub credentials in IntelliJ IDEA, the Login to GitHub dialog opens. Specify your login and password, or create a new account there.

When connection to GitHub has been established, the Share Project on GitHub dialog opens. Specify the new repository name, the name of the remote (i.e. the repository that will be hosted on GitHub and that you will sync your local repository with), and enter a description of your project's main functionality.

You can select the Private option if you do not want to allow public access to your repository for other GitHub users (note that this option is unavailable for free accounts).

Click Share to initiate a new repository and upload project sources to it.

Contribute to somebody else's projects

If you want to contribute to a project hosted on GitHub that you do not have rights to push to, follow this workflow:

Create a fork of the project you want to contribute to, i.e. a copy of the original repository on GitHub.

When you are ready to share the results of your work, rebase your fork on the current HEAD of the master branch in the original project to make sure your changes do not conflict with new commits that were pushed after you created your fork.

Create a pull request so that you can tell others about the changes you've made, and ask for comments or review. Note that a pull request is merged into the original repository only after approval.

Fork a project

A copy of the original project will be created under your account. To make changes to this project, you need to clone it to create a local repository.

Watch this video tutorial on how to keep your fork of a project up to date:

Rebase a fork

From the main menu, choose VCS | Git | Rebase my GitHub fork. Your fork will be rebased onto the HEAD commit in the master branch of the original project your created your fork from.

Create a pull request

By creating a pull request, you tell others about the changes you've pushed to your fork, so that they can be reviewed, discussed, and integrated into the base branch. To create a pull request, do the following:

Under Base Fork, specify the project that you want to send the pull request to. Either select a repository from the list populated by IntelliJ IDEA, or click Select Other Fork.

Under Base Branch, specify the branch in the target project that your changes will be applied to. Click Show Diff to review the list of commits that will be included in the pull request. To view a commit details, select it and switch to the Log tab of the Version Control tool window, where you can see a list of files included in the selected commit, view diff, etc.

Specify the name for your pull request in the Title field, and, optionally, provide a description of the changes to be applied through your request.

Share code by using gists

Gists allow you to share your code. You can share code snippets, entire files, or even applications. You can also use gists to save and share console output when running, debugging, or testing your code.

To create a gist, do the following:

Select a code fragment in the editor, or files and folders in the Project tool window. To save console output to a gist, right-click anywhere in the tool window or tab that contains that output.

On the context menu of the selection, choose Create Gist.

In the Create Gist dialog that opens, specify the name for your gist under Filename, and enter a description of the code you are going to publish.

Select the Private option to create the so-called secret gist. Secret gists are not searchable and do not show up in Discover. They can only be used for your own purposes, as you cannot share them.

If you want to create a public gist, make sure this option is deselected. Public gists are searchable, and they show up in Discover where people can browse newly appearing gists. Use public gists if you want other people to be able to find and see your code.

If you want to create an anonymous gist, select the Anonymous option. Anonymous gists can be both public or private.

If you want to open the newly created gist in your default browser, select the Open in browser option and click OK.

Once you have created a gist, you cannot convert it from secret to public or vice versa.

You cannot delete an anonymous gist from a web browser. To have it deleted, you will need to contact GitHub support and provide them with the URL of the gist you want to remove.

Jump to the GitHub version of a file

You can jump from IntelliJ IDEA to the GitHub version of a file. IntelliJ IDEA detects which branch is currently active as well as the latest revision of the file, and opens the GitHub copy of the selected file in the corresponding commit in your web browser. If you are opening the GitHub file version from the editor, the file will be also automatically scrolled to the current line.

To view the remote copy of a file, select it in the editor or in the Project view, and choose Open on GitHub from the context menu or from the Ctrl+Shift+A popup. The remote version of the file in will open in the browser.