This article describes the optimal sequence for pushing code from one branch to another with PyCharm/IntelliJ. If you need to push commits from one branch(lets call it development) to another (i.e master) using PyCharm/IntelliJ you need to follow several steps in order to ensure that all branches are synchronized properly. Otherwise you can finish with data loss, unsynchronized branches or mixture of code versions and branches. This steps are based on PyCharm/IntelliJ community edition 2018.1

This are the steps that I follow for pushing commits from development to master:

  1. Update master (the target workspace) with latest changes
  2. Merge master into development(to avoid conflicts)
  3. Push the code to master

branches_development_master

1. Update master (the target workspace) with latest changes:

This are the steps which can be done from the PyCharm/IntelliJ menus or bottom toolbar.

  • Check out as master
    • the right bottom corner select master (Local Branch)
    • Checkout
  • Pull latest changes
    • VCS
    • Git
    • Pull

checkout_master

If you like to use the terminal the commands are:

git checkout master
git pull origin master

2. Merge master into development(to avoid conflicts):

Now it's time to merge all changes(if any) from master to development. The idea is to avoid conflicts from changes which are on master but not on development. This can be done by:

  • Check out as development
    • the right bottom corner select development (Local Branch)
    • Checkout
  • Merge into current
    • the right bottom corner select master (Local Branch)
    • Click on it to show additional menu
    • Merge into current
  • Push the merge to development (remote) - optional step
    • VCS
    • Git
    • Push

merge_into_current

The terminal commands:

git checkout development
git merge master
git push origin development

3. Push the code to master

Once development is synchronized with master you can push your changes. This can be done by:

  • Check out as master
    • the right bottom corner select master (Local Branch)
    • Checkout
  • Merge into current
    • the right bottom corner select development (Local Branch)
    • Click on it to show additional menu
    • Merge into current
  • Push the changes to master (remote)
    • VCS
    • Git
    • Push

The terminal equivalent is:

git checkout master
git merge development
git push origin master

Note: if you are doing this for first time my advice is to test it in separate environment where you can see the steps and see the changes on the branches. If you want to do it in production then be cautious because changing the steps can cause problems.