Answer a question

I realized that after a commit in VSCode there's a "Push" menu option that pushes the commit to the default branch.

However, I often need to push it as well to different branches. Is there a way to do this or run git push --progress "origin" DEFAULT_BRANCH:OTHER_BRANCH through VSCode?

Answers

Update 2021-02-12

On the Source Control tab (Ctrl+Shift+G), press ⃛ to access Git commands dropdown menu, or simply use F1 and type the Git command:

  1. Switch to the branch to push – Branch > Create Branch OR Checkout to... > ➕ Create New Branch
  2. Stage your changes – ➕ button above the files list OR Changes > Stage All Changes (several Git: options available)
  3. Commit your changes – ✓ top left button OR Commit
  4. Push the new branch: Branch > Publish Branch

Push command is now for branches already pushed to remote.

Update 2019-08-16

VS Code now has a specific option to allow a Push to... a specific remote (not a branch) through the ... (hover the repo in the source control tab Ctrl+Shift+G) OR through F1+type push to.

TLDR; (re-answering the question)

  1. switch to the branch to push – F1+ type Checkout to... (instead of the old Git Branch option) or choose a Create Branch option
  2. Stage your changes – F1+ type stage (choose one of the Git: options)
  3. Commit your changes – F1+commit
  4. F1+Git: Push pushes the branch you previously created or checked out (using the same name).

Original answer

After all it's possible, this is a non direct way of pushing into another branch with VSCode, so answering my own question:

  1. Switch to the other branch – F1+Git Branch+ENTER, type the name of the branch and press ENTER again (once the exact name of the branch is typed, it will show its id in the autocomplete dropdown or inform you that that's the current branch);
  2. Stage your changes by selecting the files for commit;
  3. Commit the staged files (or all) and click ... and Push.

You can later switch back to your initial branch with F1+Git Branch+ENTER+[branch name]+ENTER. The only problem with this is that VSCode does not allow you to push again those same changes back to the initial branch (even with F1+Git Push).

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐