CPHPython
CPHPython

Reputation: 13759

How to git push to a different branch with Visual Studio Code?

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?

Upvotes: 26

Views: 113629

Answers (2)

Abu-Bakkar
Abu-Bakkar

Reputation: 1

git push an existing project to GitHub git init git add . git commit -m "Add existing project files to Git" git remote add origin https://github.com/cameronmcnz/example-website.git git push -u -f origin master

Upvotes: -1

CPHPython
CPHPython

Reputation: 13759

Update 2022-12-27

On the Source Control tab (Ctrl++G or ^++G on Mac), press to access Git commands dropdown menu:

  1. Switch to the branch to push – Branch > Create Branch OR Checkout to... > ➕ Create New Branch

    Commit & Push button

  2. Press the Commit & Push button (if not visible, press under the Message text box)

  3. two popups will show up for you to confirm staging, committing and pushing of your changes to this new branch

Confirm & commit unstaged changes Publish and push new branch

Alternative using only menu options:

  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 (or just use the Push option and press OK in the popup)

All above options can be accessed through commands F1 (Mac: fn+F1 or ++P) and typing git [command], e.g. "git checkout".

For previous versions, check this answer's timeline.

Upvotes: 39

Related Questions