DEV Community

Cover image for Step-by-Step Guide to Creating Github Repositories and Adding Files Using the VSCode Terminal
Praise Immanuel
Praise Immanuel

Posted on

Step-by-Step Guide to Creating Github Repositories and Adding Files Using the VSCode Terminal

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.

  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

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

Enter fullscreen mode Exit fullscreen mode
git config --global user.email "youremail@example.com"

Enter fullscreen mode Exit fullscreen mode

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.

  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

  1. 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.
  1. Once you've filled in the necessary details, click the "Create repository" button at the bottom of the page.

Create Repository

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
Enter fullscreen mode Exit fullscreen mode

git init

  • 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 .
Enter fullscreen mode Exit fullscreen mode

Add files to github

  • Commit your changes with a meaningful commit message using the git commit command:
git commit -m 'Initialize Repo'
Enter fullscreen mode Exit fullscreen mode

Commit to git

  • 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>
Enter fullscreen mode Exit fullscreen mode

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

  • Push your local repository to GitHub using the git push command:
git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Push to github

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.

Top comments (0)