Step-by-Step Guide to Creating Github Repositories and Adding Files Using the VSCode Terminal
Tags: webdev, github, frontend, development
Published: 2023-11-06 09:00:43

Creating a GitHub repository and adding files using the terminal is a fundamental skill for any developer. GitHub is a popular platform for version control, collaboration, and sharing of code. In this detailed guide, I will lead you through the step-by-step procedure of establishing a GitHub repository and incorporating files into it using the command line. For illustration, I'll be using screenshots from a sample project I've already set up, but you'll be applying these steps to your own projects.

## Prerequisites

Before you start, make sure you have the following prerequisites in place:

1. 
Git: Install Git if you haven't already. You can download it from the official website: [Git Downloads](https://gitscm.com/downloads).

2. 
GitHub Account: You'll need a GitHub account. If you don't have one, you can sign up at GitHub.


## Step 1: Setting Up Git

Before you create a GitHub repository, ensure that Git is properly configured on your local machine, specifically within the VS Code terminal. Open your terminal within VS Code and run the following commands subsequently to set your Git username and email

![Create New Terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dwp23yhvwny83ipdzptb.png)

```
git config --global user.name "Your Name"

```

```
git config --global user.email "youremail@example.com"

```
Replace "Your Name" and "youremail@example.com" with your _**GitHub username and email.**_


## Step 2: Create a GitHub Repository

1. Open your web browser and go to [GitHub](https://github.com/).

2. Sign in to your GitHub account if you're not already logged in.

3. Navigate to the top-right corner of the GitHub interface and click on the '+' icon. From the dropdown menu, choose 'New repository' or simply click on the green 'New' button on the Left hand side.


![Github User Dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t690h68y3l890v5rxn68.PNG)


4. On the "Create a new repository" page, you'll need to provide the following information.

- Repository Name: Enter a unique name for your new repository.
- Description (Optional): Add a brief description to help others understand the purpose of your repository.
- Visibility: Choose between making your repository "Public" or "Private," depending on your needs.
- Initialize this repository with: You can choose to add a README file, a .gitignore file, and a license. This is optional and depends on your project's requirements.

5. Once you've filled in the necessary details, click the "Create repository" button at the bottom of the page.


![Create Repository](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mmyt3eh3aq9ruzkkxjmu.PNG)

## Step 3: Add Files to the Repository

1. Navigate to the directory where your project files are located by opening the folder from which you want to add files in VS Code and opening a new terminal following the initial Step 1.

2. Initialize a Git repository in your project folder:

```
git init
```


![git init](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pn9qozm6hzpluhz2jas3.PNG)

- 
Add your files to the Git staging area using the git add command. You can add individual files or all files in the directory using wildcards. To add all files, use:

```
git add .
```


![Add files to github](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxutitfbqvckiv0c323k.PNG)


- 
Commit your changes with a meaningful commit message using the git commit command:

```
git commit -m 'Initialize Repo'
```


![Commit to git](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qlxdd5lnvfjfrneg0zbg.PNG)

- 
Link your local Git repository to the GitHub repository you created earlier. You can do this using the git remote command:
```
git remote add origin <repository-url>
```

_You will need to replace the provided code above with the code displayed in the screenshot from your own new repository page_


![Add Remote Origin git](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pr81b4hieeuh5muk42za.PNG)

- 
Push your local repository to GitHub using the git push command:

```
git push -u origin main
```

![Push to github](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/anv07kirfw42to84zzev.PNG)

### Conclusion
Congratulations! You've successfully created a GitHub repository and added files to it using the terminal. This process is essential for managing your code, collaborating with others, and sharing your projects on GitHub. With these skills, you can efficiently work on and contribute to open-source projects or host your own code for the world to see and use. Feel free to leave a feedback if you have any questions.