Pushing code to GitHub means moving your code files from a local repository to a remote repository, i.e., GitHub. This article shows you how to push code from Visual Studio Code to GitHub.
Firstly, you need to have Git installed on your system. Git will give us the underlying technology which powers GitHub. Go to git-scm.com/downloads and choose the download for your operating system. Then, install it with default settings.
Secondly, make sure to have an account on GitHub. Go to github.com, and sign in to your account.
How To Push Code From Visual Studio Code To GitHub?
Step 1: Create A GitHub Repository
- Log in to your GitHub account.
- Click on the + icon on the top-right to create a new repository.
- Enter a repository name and click on the Create repository button.
- Once your repository is created, copy the web URL. This URL allows us to push code to this repository from VS Code.
Step 2: Open An Existing Project With VS Code
- From the “Explorers” tab in the sidebar, click on the Open Folder button.
- Open the folder from your preferred directory.
- Once the folder is opened, you’ll see all the source files.
Note: Make sure that all the code files are in one folder, as you’ll have to push your folder to GitHub.
Step 3: Commit The Code Files
- Click on the Initialize Repository button from the “Source Control” tab in the sidebar.
- Now, under the Source Control panel, enter any commit message. I’m going to type “First Commit.” Then, click on the ✓ icon next to Source Control heading or press Ctrl + Enter.
- When prompted with a pop-up as shown in the image below, choose Yes.
Step 4: Push Code From Visual Studio Code To GitHub
- Inside the Source Control panel, click on the Overflow button with the ellipsis icon. Then, from the Pull, Push menu option, select Push to.
- On the right corner, you will be prompted to add a remote. Click on Add Remote button.
- Next, on the top-center, a palette will appear. Paste the copied GitHub repository URL and press Enter.
- Then, type any remote name and press Enter.
- Open the Push to sub-menu option again. Then, choose your repository path and press Enter.
- A pop-up will appear to log in to GitHub. Choose which option you’ll use to sign – I’m using my browser.
- An authorization page will pop up in the browser. Click on the GitCredentialManager button.
- Enter the GitHub password.
- Finally, refresh your GitHub repository URL.
You will notice that the codes are successfully pushed to GitHub from your local repository.