14

What is the VS Code stage changes shortcut?

I mean is it possible to stage a selected file without clicking the plus button in the version control tab?

enter image description here

Maybe there is no shortcut an it is somehow possible to setup one?

qqqqqqq
  • 1,831
  • 1
  • 18
  • 48
  • Additional note for anyone who struggled with the accepted answer, note that you need to OPEN the file to be staged in the diff editor (where you compare the versions of the file before and after the change), with your cursor active in the diff editor. Once there, the keyboard shortcuts to stage/unstage that you set will work. In the keyboard shortcuts settings, note that the default is to have the keybinding active when "isInDiffEditor" is true. – Jason A Oct 07 '21 at 06:38

4 Answers4

19

My custom workflow:

  1. Open the SCM view ctrl+shift+G
  2. Select the file in SCM using up/down arrow keys
  3. Diff the file spacebar
  4. Stage the file ctrl+up
  5. Diff the file spacebar
  6. Stage the file ctrl+up

How to configure?

Preferences: Open Keyboard shortcuts (JSON) command: workbench.action.openGlobalKeybindingsFile
Then put in the following:

    {
        "key": "ctrl+up",
        "command": "git.stage",
        "when": "workbench.scm.active"
    }
Paulius Zaliaduonis
  • 5,059
  • 3
  • 28
  • 23
9

git.Stage and git.StageAll. They have no keybinding assigned by default. You can assign a custom one in your keyboard shortcut settings. CMDK+CMDS

hotpink
  • 2,882
  • 1
  • 12
  • 15
  • Could you, please, let me know how did you find the commands? Did you just checked the settings shortcuts or did you read a manual somewhere? – qqqqqqq Dec 30 '19 at 22:53
  • 1
    Opening your keyboard settings like mentioned above will bring up a search field. I typed "stage" in there to filter for the relevant commands. Alternatively, if you want to view all Git commands, type "git". Also incredibly useful is the keyboard icon on the right end of that search field. Click on that and enter any keyboard shortcut and VS Code will list all the commands currently attached to that. – hotpink Dec 30 '19 at 22:59
  • 2
    This didn't work for me without selecting the file in scm using a mouse click. Selecting with keyboard only then using the keyboard shortcut didn't have any effect – sam Sep 23 '20 at 13:47
  • 1
    `git.Stage` works on an **open file or comparison**, not a filename in the SCM view. – wjandrea Jan 06 '23 at 21:51
4

for those who interested in stageAll / unstageAll, you can also do these as well

[
    {
        "key": "ctrl+up",
        "command": "git.stageAll",
    },
    {
        "key": "ctrl+down",
        "command": "git.unstageAll",
    }
]
  1. CTRL/CMD+SHIFT+P
  2. Open Keyboard Shortcuts (JSON)
  3. Place your key bindings
Jonathan
  • 1,955
  • 5
  • 30
  • 50
HoseinGhanbari
  • 1,058
  • 1
  • 11
  • 23
2

I know you are looking for a keyboard shortcut and I was too. However, I have found that the use of the command palette is a much more efficient and cleaner workflow:

  1. open command palette Ctrl+Shift+P.
  2. type in "git stage".

I offer this as an alternative if anyone is looking.

kmacdonald
  • 3,381
  • 2
  • 18
  • 22