4

I'd like to have single keyboard shortcut do to two things in IntelliJ IDEA:

  • switch to master branch in Git regardless of current branch (git checkout master)
  • pull latest changes from origin/master (git pull --rebase --autostash origin master)

Currently I have both configured as External Tool and I have separate shortcuts attached. How can I join these commands so I can prepare my local master branch for further development within one keyboard shortcut?

Or maybe there is a way to do the same without using External Tool feature?

Michal Kordas
  • 10,475
  • 7
  • 58
  • 103
  • What happens if you give both those commands in the same External Tool, separated by a semi-colon – Bajal May 24 '19 at 19:36
  • 1
    I don't use IntelliJ IDEA but, as long as you can execute a git command, you'll surely be able to define a git alias https://stackoverflow.com/questions/7534184/git-alias-multiple-commands-and-parameters – ludovico May 24 '19 at 20:20
  • @Bajal If I separate by semicolon then I get `git: 'checkout master;' is not a git command. See 'git --help'.` – Michal Kordas May 24 '19 at 21:12
  • @ludovico great idea, you can post it as an answer – Michal Kordas May 24 '19 at 21:16
  • I guess Romain's answer gets you covered. Alternatively, you can define your alias in a .gitconfig file (https://stackoverflow.com/a/2553799/11298742). Another one is definning a shell alias ;) – ludovico May 26 '19 at 16:18

2 Answers2

3

In case you didn't already come up with a good alias for that after ludovico's insightful comment, here's one named qp for "quick pull" but rename it as you prefer.

git config --global alias.qp '!f() { git checkout ${1-master}; git pull --rebase --autostash origin ${1-master}; }; f'

which you can use with or without a branch parameter :

# default usage (targets master)
git qp

# but if you ever need the same action for another branch
git qp some-feature-branch
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
2

There is no UI action to do what you need, unfortunately. See https://youtrack.jetbrains.com/issue/IDEA-171649 and related.

As a workaround, you can build a git alias (as mentioned in other replies) and use it as an external tool with a shortcut.

Dmitrii Smirnov
  • 7,073
  • 1
  • 19
  • 29