A Beginner's Guide to Git and GitHub
Source: Dev.to
If you have ever saved a file as final_project.py, then final_project_v2.py, and eventually final_project_v3.py, you have experienced the manual version of version control. It’s messy, confusing, and prone to errors. In this article we’ll show how using Git and GitHub lets you manage your code professionally.
Benefits of Using Git and GitHub
- Collaboration – Multiple people can work on the same project without overwriting each other’s code.
- Undo mistakes – Revert to a previous version if your code breaks.
- Experimentation – Create a branch to try out a new feature without interfering with the main project.
Tracking Changes Using Git
Step A: Initialize your project
git init
Step B: The Staging Area
Add a specific file:
git add filename.py
Add everything:
git add .
Step C: Commit the changes
git commit -m "Add login functionality"
Pushing Code to GitHub
-
Create a repository – Go to GitHub, click New Repository, give it a name, and click Create.
-
Link your local Git to GitHub – Copy the URL of your new repo and run:
git remote add origin https://github.com/your-username/your-repo-name.git -
Push your code:
git push -u origin main
Pulling Code from GitHub
When working in a team or from a different computer, pull the latest changes from GitHub to your local machine:
git pull origin main
Version control might feel like extra work, but it’s the ultimate safety net for developers.