PhpStorm 2019.3 Help

Commit and push changes

After you've added new files to the Git repository, or modified files that are already under Git version control and you are happy with their current state, you can share the results of your work. This involves committing them locally to record the snapshot of your repository to the project history, and then pushing them to the remote repository so that they become available to others.

Commit changes locally

  1. Select the files you want to commit or an entire changelist in the Local Changes tab of the Version Control window Alt+9 and press Ctrl+K or click Commit Commit button on the toolbar.

    The Commit Changes dialog that opens lists all files that have been modified since the last commit, as well as all newly added unversioned files.

  2. Review the list of files to be committed, clear checkboxes next to files and directories that you don't want to include in the commit. Changes in the excluded files will remain in the active changelist and you can commit them later.

    You can also select files in Unversioned Files — PhpStorm will stage and commit these files in one step.

  3. Enter a meaningful commit message.

    You can click Commit Message history Commit Message history Ctrl+M to choose from the list of recent commit messages.

    You can also edit the commit message later before you've pushed your commit.

  4. If necessary, you can commit with advanced options. These options are available on the right-hand side of the dialog:

    • Author: if you are committing changes made by another person, you can specify the author of these changes.

    • Amend commit: lets you add local changes to the previous commit.

    • Sign-off commit: select if you want to sign off your commit to certify that the changes you are about to check in have been made by you, or that you take the responsibility for the code you're committing.

      When this option is enabled, the following line is automatically added at the end of the commit message: Signed off by: <username>

    • In the Before Commit area, select actions you want PhpStorm to perform before committing the selected files to the local repository.

    • In the Upload files to list of the After Commit area, select the server access configuration or a server group to use for uploading the committed files to a local or remote host, a mounted disk, or a directory. See Deploying your application for details.

  5. Click Commit or click the button selector to display the available commit options:

    • Commit and Push Ctrl+Alt+K: push the changes to the remote repository immediately after the commit — before pushing, you will be able to review the current commit as well as all commits that were not pushed to the remote.

    • Create Patch: generate a patch based on the changes you are about to commit. In the Create Patch dialog that opens, type the name of the patch file and specify whether you need a reverse patch.

    • Remote Run: run your personal build. This option is only available when you are logged in to TeamCity. Refer to TeamCity plugin documentation for details.

When you decide what to commit, you can choose not only which new and modified files to commit, but also which specific changes in a single file should be committed.

Select changes in file to commit

  1. Select the files you want to commit or an entire changelist in the Local Changes tab of the Version Control window Alt+9 and press Ctrl+K or click Commit Commit button on the toolbar.

    The Commit Changes dialog that opens lists all files that have been modified since the last commit, as well as all newly added unversioned files.

  2. In the Commit Changes dialog, select a file that you want to commit partially. A diff view for this file wll appear at the bottom of the dialog.

  3. In the diff view, select which changes should be included into the commit:

    • Use checkboxes next to each change that you want to commit.

    • Right-click a change and use the context menu commands: Include Lines into Commit and Include Only These Lines into Commit.

    • Select Move to Another Changelist Shift+Alt+M from the context menu of a change and select a changelist for this change.
      You can also make the selected changelist active, so that all changes that you make after that will fall into that changelist, while any modifications you made before that will stay where they are.

    Partial commit dialog
  4. Click Commit. Unselected changes will stay in the current changelist, so that you can commit them separately.

Push changes to a remote repository

Before pushing your changes, sync with the remote and make sure your local copy of the repository is up-to-date to avoid conflicts.

PhpStorm allows you to upload changes from the current branch to its tracked branch or to any other remote branch.

  1. Press Ctrl+Shift+K or choose VCS | Git | Push from the main menu. 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).

  2. 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. It will be saved and you can edit it later via VCS | Git | Remotes (for details, see Add a remote repository).

  3. If you want to modify the target branch where you want to push, you can click the branch name. The label turns into a text field where you can type an existing branch name, or create a new branch. 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.

  4. 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.

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

    These choice options are only available if the current branch is not listed in the Protected branches field (see Version Control Settings: Git), otherwise, you can only perform the push operation.

Update your working copy if push is rejected

If push is rejected because your working copy is outdated, PhpStorm displays the Push Rejected dialog, provided that the Auto-update if push of the current branch was rejected option in the Git settings page of the Settings Preferences dialog is not selected. Do the following:

  1. 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.

  2. If you want PhpStorm 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 checkbox in the Git settings page of the Settings Preferences dialog will be selected, and the applied update method will become the default one.

    To change the update strategy, deselect this option to invoke the Push Rejected dialog the 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.

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

When do I need to use force push?

When you run push, Git 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 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 then need to merge.

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

Last modified: 13 December 2019