VS Code stage changes shortcut
Asked Answered
C

4

20

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?

Corettacorette answered 30/12, 2019 at 22:19 Comment(1)
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.Razee
I
11

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

Ignominious answered 30/12, 2019 at 22:49 Comment(4)
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?Corettacorette
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.Ignominious
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 effectInapprehensive
git.Stage works on an open file or comparison, not a filename in the SCM view.Heredity
O
27

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"
    }
Owensby answered 13/7, 2021 at 7:39 Comment(1)
I love this and use it a ton, but in early 2024 a VSCode update partially broke the feature by losing item focus after each file is staged making it slow to stage multiple files via this keyboard shortcut. there's a ticket to track the issue github.com/microsoft/vscode/issues/207066Oblivion
I
11

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

Ignominious answered 30/12, 2019 at 22:49 Comment(4)
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?Corettacorette
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.Ignominious
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 effectInapprehensive
git.Stage works on an open file or comparison, not a filename in the SCM view.Heredity
C
5

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
Carlyle answered 15/8, 2021 at 3:54 Comment(0)
T
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.

Thirtytwomo answered 5/11, 2021 at 18:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.