GitHub is the world’s most popular platform for hosting and sharing code. Whether you’re a solo developer or working on a team, uploading your code to GitHub ensures version control, collaboration, and backup of your projects.
In this blog post, we’ll walk you through how to upload your code to GitHub—using both the command line and GitHub’s web interface.
🧰 Prerequisites
Before you start, make sure:
- You have a GitHub account: https://github.com
- Git is installed on your machine: https://git-scm.com
- You have a local project folder ready to upload
📦 Method 1: Upload Code Using Git Command Line
Step 1: Initialize Git in Your Project Folder
Navigate to your project directory in the terminal:
cd path/to/your/project
Initialize Git:
git init
Step 2: Add and Commit Files
Stage your files:
git add .
Commit them:
git commit -m "Initial commit"
Step 3: Create a New Repository on GitHub
- Log in to GitHub.
- Click the + icon in the top right > New repository.
- Enter a name and choose visibility (Public/Private).
- Do not initialize with a README (since we already have files locally).
Copy the repository URL (HTTPS or SSH).
Step 4: Link Your Local Repository to GitHub
git remote add origin https://github.com/yourusername/repo-name.git
Step 5: Push to GitHub
Push your local code to the remote GitHub repository:
git push -u origin master
Note: For newer Git versions, the default branch might be
main
instead ofmaster
.
🖱️ Method 2: Upload Code Using GitHub Website (Drag & Drop)
This is ideal for quick uploads of small projects or files.
Step 1: Create a New Repository
- Go to GitHub > New Repository
- Fill in the name and description
- Initialize with a README (optional)
Step 2: Upload Files
- Once the repository is created, click Add file > Upload files
- Drag and drop your files, or select them using the file picker
- Add a commit message
- Click Commit changes
You’re done!
💡 Best Practices
- Use
.gitignore
to exclude unnecessary files (e.g.,node_modules
,.env
) - Commit regularly with meaningful messages
- Use branches for features and bug fixes
- Add a
README.md
to describe your project - Use tags or releases for versioning
🧪 Troubleshooting
- Authentication errors? You may need to set up a Personal Access Token if using HTTPS.
- Push rejected? Ensure the remote branch doesn’t already have conflicting commits.
- Permission denied (SSH)? Check if your SSH key is added to GitHub.
✅ Conclusion
Uploading code to GitHub is a vital step in modern development workflows. Whether you’re using the command line or the GitHub web UI, the process is straightforward and ensures your code is accessible, version-controlled, and ready for collaboration.