3

Is it possible to automatically git push when I make a commit in Visual Studio 2022? I see the Commit All button by default, and I don't want to have to click the arrow beside it every time that I want to commit & push at the same time, which is the action I always do when I commit.

Visual Studio Code has a nice setting for this, but I didn't see a similar settings to configure it in Visual Studio.

Timothy G.
  • 6,335
  • 7
  • 30
  • 46
  • 3
    I do not think you will find stuff like that anywhere out-of-the-box because one of the tenets of DVCS is to be able to keep your stuff private. If it's such a pain for you, you might want to develop a git alias (or a plugin/extension.... those are also fancy) or a full-blown script that does commit/push in a single action.... considering how often I do `git commit --amend` after committing, I wonder if this is a good idea overall but..... – eftshift0 Jun 17 '23 at 07:24
  • @eftshift0 [Eclipse offers dedicated Commit and push button out of box](https://stackoverflow.com/a/38920593/7860670) Very convenient – user7860670 Jun 17 '23 at 08:29
  • @eftshift0 I review the diff of each file before I commit, and that helps me to avoid having to amend. Vsc and vs both have a nice looking diff built-in. – Matthew Kooshad Jun 17 '23 at 13:17

1 Answers1

2

You can assign a keyboard shortcut to perform the commit and push instead of just commit.

Go to Tools → Options → Environment → Keyboard and optionally search the word "commit". Find the Team.Git.CommitAndPush shortcut and set it to what you wish. In this case, I remapped Team.Git.Commit (normally Ctrl + Enter) to Team.Git.CommitAndPush. When assigning the shortcut, be sure to select "Git" for the "use new shortcut in" drop down.

keyboard shortcut to set commit and push

After changing this, you can see that the drop down option now has the shortcut too:

commit and push drop down option with shortcut keys listed

Timothy G.
  • 6,335
  • 7
  • 30
  • 46