Once you’ve made changes to your local project—whether it’s fixing bugs, adding features, or updating documentation—you’ll want to sync those updates with GitHub. This ensures your remote repository reflects the latest version of your work and is available for collaborators or deployment.
In this guide, you’ll learn how to update your project on GitHub using Git.
✅ Prerequisites
Before you begin:
- Git must be installed on your system
- You should have a local Git repository connected to GitHub
- You must have changes committed locally
🔹 Step 1: Make Changes Locally
Edit, add, or delete files in your project directory as needed.
Example: Add a new file
touch new-feature.js
🔹 Step 2: Stage Your Changes
Stage the files you want to update:
git add .
Use
.
to stage all changes, or specify file names individually:
git add file1.js file2.html
🔹 Step 3: Commit the Changes
Create a commit with a meaningful message:
git commit -m "Add new feature for user login"
🔹 Step 4: Push Changes to GitHub
Push the committed changes to your GitHub repository:
git push origin main
Replace
main
with your current branch name if different (e.g.,master
,dev
).
🔁 Optional: Pull Before You Push
If you’re working in a team, always pull the latest updates before pushing to avoid conflicts:
git pull origin main
Resolve any conflicts, commit again, and then push.
🔧 Troubleshooting: Authentication Issues
If you’re prompted for a username/password or token:
- For HTTPS: Use your GitHub personal access token (PAT) instead of a password.
- For SSH: Ensure your SSH key is added to your GitHub account.
✅ Summary
Step | Command |
---|---|
Stage changes | git add . |
Commit changes | git commit -m "message" |
Push to GitHub | git push origin main |
Pull before push | git pull origin main |
🚀 Final Thoughts
Keeping your GitHub project up to date is essential for collaboration, version control, and deployment. By following these Git commands regularly, you ensure your project remains organized, shareable, and easy to maintain.