Git is a version control system that records changes to files. GitHub is a platform that can host Git repositories and provide collaboration features. Together they are widely useful for managing web development projects.
Git vs GitHub
Git runs on your computer and tracks changes in a repository. GitHub is an online service where repositories can be stored and shared. You can use Git without GitHub, although GitHub is convenient for remote repositories and collaboration.
1. Create or download a repository
For an existing project, clone its repository:
git clone https://github.com/username/project.git
cd project
2. Check the current state
git status
This command shows modified, added and untracked files. Running it before a commit helps you understand exactly what will be recorded.
3. Stage changes
git add index.php
git add assets/
You can stage specific files or use git add . when you have reviewed all changes and intentionally want to stage them.
4. Create a commit
git commit -m "Improve contact form validation"
A commit is a recorded checkpoint. Good commit messages describe the change clearly.
5. Push changes
git push origin main
This sends your local commits to the remote repository. The branch name may be different in another project.
6. Pull changes
git pull origin main
Pulling before starting work can reduce conflicts when several people are working on the same project.
7. Use branches for larger changes
git checkout -b feature/contact-form
A feature branch lets you work separately from the main branch. After testing, the changes can be reviewed and merged.
8. Protect sensitive information
Never commit passwords, database credentials, private API keys or secret configuration values. Use environment variables or protected configuration files where appropriate, and add sensitive files to .gitignore.
9. A simple daily workflow
- Pull the latest changes.
- Create or switch to the appropriate branch.
- Make a small, focused change.
- Test the website.
- Run
git statusand review the changed files. - Commit with a clear message.
- Push the branch or changes.
Conclusion
Git becomes much easier when you understand the basic cycle: edit, review, stage, commit and push. Start with small commits and learn branching as your projects become more collaborative.