77

In VS Code, the only way that I know of to push commits with git is to go into the "..." menu of the Source Control tab and click Push.

Exhibit A

That method seems a bit roundabout to me, especially considering that there is a unique button to commit code right in the tab. Is there a way to have a push button be next to the commit button in VS Code Source Control?

2
  • The idea is that commit is a much more common and less impactful operation than push. Commented Oct 27, 2024 at 8:38
  • stackoverflow.com/a/73321308/6227407 Commented Dec 30, 2024 at 14:38

5 Answers 5

103

There is a button at the bottom left of the VS Code editor, which you can click to automatically sync your branch with that from remote (i.e. both pull AND push, merging your branch with upstream if necessary). This might or might not be what you want, but it's easy to click this when you know that there are no changes upstream (e.g. when you're working on a project by yourself).

Otherwise, I frequently bring up the Command Palette with ⇧⌘P (Ctrl-Shift-P on Windows/Linux) and type gpus, which brings up Git: Push as the first option. (It's been ingrained in my fingers since the days of Sublime Text)

If you are using the later versions of VS Code which has MRU list of command history, you can shorten it even further and just type gp, which is exactly what I've been using since SublimeGit in Sublime Text.

Lastly, another option you may want is to add a custom keyboard shortcut to push changes. You can do this by editing your Keyboard Shortcuts File, and adding something like the following:

{ { "key": "ctrl+alt+p", "command": "git.push" } } 
Sign up to request clarification or add additional context in comments.

5 Comments

Yeah, I guess this works. I would have liked a button in the Source Control tab, but this works too.
Personally I find that the Command Palette method is the most productive one for me, just fyi!
@ifconfig and Irvine is there a hotkey to commit and push at same time? Right now if i type in to the git sideview comment, and hit ctrl + enter, it just commits it, it doesnt push it at same time.
The integrated Keyboard Shortcuts customization tool is great too. Open it with Ctrl+K Ctrl+S
The sync option used to work for me, but not anymore. Now, when I have commits to push it first tries to pull and then fails due to some uncommitted files.
59

There is a new setting Post Commit Command in vscode 1.30.1 to change the default commit behavior:

enter image description here

3 Comments

For anyone that can't find it, it's under File>Preferences>Settings>Extensions>Git
Can also use Ctrl+Comma to bring up settings (guessing that would be Cmd+Comma for Macs). That seems to be the new normal for settings in Microsoft products (also works in Windows Terminal)
This is an awesome feature. Hats off to vs code devs.
17

VS Code has it there but you have to activate it:

  1. Go to shortcuts by Command/Ctrl + K + Command/Ctrl + S

  2. Then search for "Git Push"

  3. Click on the + that appears when you hover over it

  4. Finally write the keyboard shortcut you want

You can also search for "Git Pull", "Git commit", and even things not related to Git like "kill terminal" or "expand terminal".

Comments

1

You can create your own shortcut after doing Ctrl + Shift + P. I have shown it in the pictures below.

  1. Ctrl + Shift + P

  2. You can write "git push" to search.

  3. Click in front of git push "Settings Icon". enter image description here

  4. Click "Edit Icon". enter image description here

  5. Then you can write. For example (Ctrl + q).

1 Comment

Could you use proper screenshots?
1

Clean workflow:

Press Ctrl + K + S to open the shortcut editor.

I spent some time reading the docs to have a really handy shortcut:

enter image description here

The main thing here is the When condition focusedView == 'workbench.scm', this shortcut will only work when you are focusing the source control panel.

So you can quickly write your message, press Ctrl + Enter to commit (this is by default), then press right away Ctrl + Shift + Enter to push your commit, without accidentaly pushing your commits when you're editing something else.

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.