DEV Community

Cover image for How to Push Your Code from Visual Studio (Local) to GitHub Using Git the Terminal.[Beginner's Guide]
CyberHack-08
CyberHack-08

Posted on

How to Push Your Code from Visual Studio (Local) to GitHub Using Git the Terminal.[Beginner's Guide]

From your local Visual Studio files to your remote Github repo, all through the command lines.


Table of Contents.

  1. Creating your GitHub account

  2. Creating a new repository using a GitHub account

  3. Initialising your project and making your first commit

4.Linking your local repository to remote and push


Creating your GitHub account.

Suppose you don't already have a GitHub account. You would need to create an account. The steps are as follows:

  1. Go to your preferred web browser.
  2. Open https://github.com/join
  3. Enter your email address and enter a password you will remember.
  4. Create an account and enter your username and other required information. ## NOTE: You might need to verify your email using the verification link or an authentication app and make your profile look professional.


Creating a new repository.

  1. After signing in, click the + in the top right, and you will see a new repository
  2. You will fill in

    The repository name: my_new_repo
    Description (To describe your new repository or maybe the content of the repository): "My first repository"
    Select privacy: Private or Public


3.
Creating a Personal Access Token:
got to your settings then Devloper Settings then Personal Access Tokens then Tokens(classic).
Click Generate new token, then name it Then Under scopes, check repository. Then generate and copy it. Then when Git asks for your password, paste that token.


Initialising your project and making your first commit.

  1. Open your Visual Studio and create a new folder. If you don't know how to create a new folder, click on the link to direct you to a video on creating a new folder in Visual Studio. https://youtu.be/RxHRkf4Yf98?si=WlCs2Q-eeK3Zj6_U

2.
Open the terminal using the shortcut Ctrl+`, or you can click on the Terminal, then click on New Terminal.

3.

Check if your terminal has git installed using the command

"git --version"

If you get an error message, then no problem, all you have to do is install git using the command

"sudo apt install git"

4.

Configure Git with your name and email using the command:

""git config --global user.name "Your Name"
git config --global user.email "your.email@example.com""

5.

Initialising git using the command

"git init"

This command would help create an empty git repository in the current directory

6.

Adding the current files you are working on to the empty git repository using the command

"git add "

7.

Committing the file to your local repository using the command

"git commit-m "This is my first commit" "

This command would move the files to the staging area.


4.
Linking your local repository to the remote and pushing.

  1. After you create your first repository, you should get a page similar to this


Copy the command that says "Pushing an existing repository from the command line and paste it into your terminal.

This command connects your GitHub account to your terminal. The other one is for creating a new repo straight from the command line, but we’re not doing that here.

2.
To push your code to your GitHub account, use the command
"git push -u origin main"
You would be asked to enter your Username: Your GitHub username, and Password: That’s the token you created earlier when you created your new repository.

  1. Refresh your GitHub page, and you will find our repository. Then, open the repository, and you will find the file that has your code in it.

That’s it, you've just pushed your first project from your local computer to GitHub using only the terminal. Big thanks to everyone reading these articles. I appreciate you taking your time to follow through.

Top comments (0)