GitHub is a powerful platform for hosting and sharing your code. If you’re using Git Bash — a command-line interface for Git on Windows — you can easily push your local code to a GitHub repository.
This guide walks you through the complete process of pushing code to GitHub using Git Bash.
✅ Prerequisites
Before getting started, make sure you have:
- Git installed on your machine (
git --version) - A GitHub account
- A GitHub repository (either create one or use an existing one)
🛠️ Step-by-Step Guide
🔹 1. Open Git Bash
Right-click in your project folder and choose Git Bash Here, or open Git Bash manually and navigate to your project:
cd path/to/your/project
🔹 2. Initialize a Git Repository (if not already initialized)
If this is your first time using Git in the project, initialize it:
git init
🔹 3. Add Remote Origin
Link your local project to a GitHub repository:
git remote add origin https://github.com/your-username/your-repo.git
Replace the URL with your GitHub repository’s URL.
🔹 4. Add Files to Staging Area
Add all your project files:
git add .
You can also add individual files:
git add filename.ext
🔹 5. Commit the Changes
Commit your changes with a message:
git commit -m "Initial commit"
🔹 6. Push Code to GitHub
To push to the main branch:
git push -u origin main
If your default branch is
master, replacemainwithmaster.
If you’re pushing to a new branch:
git push -u origin your-branch-name
🔐 Authentication
- HTTPS: Git may prompt you for your GitHub username and personal access token.
- SSH: Ensure your SSH key is set up with GitHub for passwordless authentication.
🧠 Tips
- Use
git statusto check what’s staged or committed. - Use
git logto see commit history. - Run
git pushafter each commit to update GitHub.
✅ Summary
| Step | Command |
|---|---|
| Initialize Git | git init |
| Add remote origin | git remote add origin <repo-url> |
| Stage files | git add . |
| Commit changes | git commit -m "message" |
| Push code | git push -u origin main |
🏁 Conclusion
Pushing code to GitHub via Git Bash is an essential skill for developers. Once you’ve linked your project, the process becomes seamless for future updates. Mastering these steps will help streamline your development workflow.