DEV Community

Cover image for How To Push To A Branch On Github From Vscode

Posted on

How To Push To A Branch On Github From Vscode

If you are reading this, you will probably have heard of GitHub or are even using it. GitHub is a repository hosting server for Git. Today I would like to show you how to push a code from your vscode editor to a branch of a repository you have created on GitHub.

For the purpose of this article I will be assuming

  • you already have vscode and Gitbash installed on your PC
  • you have created a repository on GitHub
  • you want to push the code to a branch other than the master branch

open the project you want to push on your vscode editor, click on the Terminal button at the top Left corner of the screen, click on New Terminal. A new terminal will open at the bottom of the screen. follow the steps below to push your code to a new branch.

  • git init
  • git branch "name" ( where name is the name of the new branch)
  • git branch (you should see the new branch listed )
  • git checkout "name" (to select your new branch)
  • git remote add "name" "url" (to get the url open your repository on Github, click the clone or download button and copy the url)
  • git push --set-upstream "name" "name" If you encounter an error in the last step input (git push "name") it would display an error and display the right code for you below, copy the code and paste it back and your code would be uploaded to your desired branch.

Top comments (0)