Yes you can.
First you need to enable the command-line launcher:
To enable invoking PyCharm operations from the command line, follow
these steps
On macOS or UNIX:
- Make sure PyCharm is running.
- On the
main menu, choose Tools | Create Command-line Launcher. The dialog box
Create Launcher Script opens, with the suggested path and name of the
launcher script. You can accept default, or specify your own path.
Make notice of it, as you'll need it later.
- Outside of PyCharm, add the path and name of the launcher script to your path.
On Windows:
- Specify the location of the PyCharm executable
in the
Path
system environment variable. In this case, you will be
able to invoke the PyCharm executable and other PyCharm commands from
any directory.
https://www.jetbrains.com/help/pycharm/running-pycharm-as-a-diff-or-merge-command-line-tool.html
Then add the following lines to your ~/.gitconfig
:
[diff]
tool = pycharm
[difftool "pycharm"]
cmd = /usr/local/bin/charm diff "$LOCAL" "$REMOTE" && echo "Press enter to continue..." && read
[merge]
tool = pycharm
[mergetool "pycharm"]
cmd = /usr/local/bin/charm merge "$LOCAL" "$REMOTE" "$BASE" "$MERGED"
keepBackup = false
(for Windows users these details might be slightly different)