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:
Git: Install Git if you haven't already. You can download it from the official website: Git Downloads.
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
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
Open your web browser and go to GitHub.
Sign in to your GitHub account if you're not already logged in.
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.
- 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.
- Once you've filled in the necessary details, click the "Create repository" button at the bottom of the page.
Step 3: Add Files to the Repository
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.
Initialize a Git repository in your project folder:
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 .
- Commit your changes with a meaningful commit message using the git commit command:
git commit -m 'Initialize Repo'
- 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
- Push your local repository to GitHub using the git push command:
git push -u origin main
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)