2

In one git repository (workspace), I want every save committed ASAP. What is the easiest way to achieve that with VSCode?

So, when I press CTRL + S, it gets pushed upstream.

2 Answers 2

4

This can be done with plugin Run on Save

Here is the example that auto commits and pushes upstream any changes in the directory mydir:

"emeraldwalk.runonsave": {
        "commands": [
            {
                "match": "\\\\mydir\\\\",
                "isAsync": false,
                "cmd": "cd ${fileDirname}",
            }, 
            {
                "match": "\\\\mydir\\\\",
                "isAsync": false,
                "cmd": "git add -A",
            },
            {
                "match": "\\\\mydir\\\\",
                "isAsync": false,
                "cmd": "git commit -a -m \"vscode autosave\"",
            },
            {
                "match": "\\\\mydir\\\\",
                "isAsync": false,
                "cmd": "git push",
            }
        ]
    }
0
-2

One way to achieve that is via terminal on VSCode. Change to the topmost directory containing the .git file and run the following commands:

git status

This shall show you the uncommitted changes. Then run the following for the new added changes (except for the remove changes)

git add <fileName>

This shall add all the added contents to index. Run below for the remove changes.

git rm <filename>

Then, git commit -m <commit msg> to commit the changes.

1
  • I know how to do it from the CLI, that is not the point. I want ctrl + s and done.
    – majkinetor
    Commented Feb 26, 2022 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.