CLion 2017.1 Help

Pushing Changes to the Upstream (Git Push)

Git integration with CLion supports uploading changes from the current branch to its tracked branch or to any other remote branch. If push is rejected due to the lack of synchronization between your local repository and the remote storage, you can either interactively choose the strategy to update the local branch, or have CLion update it silently.

To push changes

Do the following:

From the main menu, choose VCS | Git | Push. The Push Commits dialog opens showing all Git repositories (for multi-repository projects) and listing all commits made in the current branch in each repository since the last push.

If you have a project that uses multiple repositories that are not controlled synchronously, only the current repository is selected by default. For details on how to enable synchronous repositories control refer to Version Control Settings: Git .

If necessary, you can modify the path to the remote repository by clicking it. The label turns into a text field where you can type the new path or invoke completion by pressing Ctrl+Space. If you add a new remote, it will be saved and you can edit it later via VCS | Git | Remotes (for details, see Managing Remotes).

If there are no remotes in the repository, the Define remote link appears. Click this link and specify the remote name and URL in the dialog that opens.

If you want to modify the target branch where you want to push, you can do this in the same way as for the remote repository. You can also click the Edit all targets link in the bottom right corner to edit all branch names simultaneously.

Note that you cannot change the local branch: the current branch for each selected repository will be pushed.

If you want to preview changes before pushing them, select the required commit. The right-hand pane shows the changes included in the selected commit. You can use the toolbar buttons to examine the commit details.

If the author of a commit is different from the current user, this commit is marked with an asterisk.

Click the Push button when ready and select which operation you want to perform from the drop-down menu: push or push --force.

These choice options are only available if the Allow force push option is enabled (see Version Control Settings: Git), otherwise, you can only perform the push operation.

You can also switch to the editing mode by pressing Enter or N/A for the selected element.

You can press Ctrl+Q for the selected commit to display extra info, such as the commit author, time, hash and the commit message.

If you select an entire repository, all files from all commits will be listed in the right pane.

If the same file was modified within several commits, it will only be listed once if you select these commits or the entire repository, and if you invoke the Differences Viewer for this file, all changes will be zipped together.

Using force push

When you run push, Git Mercurial will refuse to complete the operation if the remote repository has changes that you are missing and that you are going to overwrite with your local copy of the repository. Normally, you need to perform pull to synchronize with the remote before you update it with your changes.

The --force push command disables this check and lets you overwrite the remote repository, thus erasing its history and causing data loss.

A possible situation when you may still need to perform --force push is when you rebase a pushed branch and then want to push it to the remote server. In this case, when you try to push, Git Mercurial will reject your changes because the remote ref is not an ancestor of the local ref. If you perform pull in this situation, you will end up with two copies of the branch which you them need to merge.

Rebasing a pushed branch and modifying its history should be avoided unless absolutely necessary (for example, if you've accidentaly pushed some sensitive data).

Using the --force will lead to all new heads being pushed on all branches, which is likely to cause confusion for your team.

If you decide to force push the rebased branch and you are working in a team, make sure that:

Nobody has pulled your branch and done some local changes to it

All pending changes have been committed and pushed

You have the latest changes for that branch

To update a local branch if push is rejected

If push is rejected due to the lack of synchronization between the current local branch and its tracked remote branch, CLion displays the Push Rejected dialog box, provided that the Auto-update if push of the current branch was rejected check box in the Git settings page of the Settings dialog box is cleared.

If your project uses several Git repositories, specify which of them you want to update. If you want to update all repositories, no matter whether push was rejected for them or not, select the Update not rejected repositories as well option. If this option is cleared, only the affected repositories will be updated.

If you want CLion to apply the update procedure silently the next time push is rejected using the update method you choose in this dialog, select the Remember the update method choice and silently update in the future option.

After you leave this dialog, the Auto-update if push of the current branch was rejected check box in the Git settings page of the Settings dialog box will be selected, and the applied update method will become the default one.

To change the update strategy, disselect this option to invoke the Push Rejected dialog next time push of the current branch is rejected, apply a different update procedure, and select the Remember the update method choice ... option once again.

Note that if you haven't selected an update procedure from the Push Rejected dialog before, and you select the Auto-update if push of the current branch was rejected check box in the Git settings page of the Settings dialog, CLion will synchronize the local branch silently using git-merge by default.

Select the update method (rebase or merge) by clicking the Rebase or Merge button respectively.