In this lesson, you will learn how to use Git and GitHub as the definitive "Source of Truth" to keep your project files consistent, regardless of where you are working.
Why You Need a Single Source of Truth
When you work on a project across multiple computers—or even just save files to different folders like project_final, project_final_v2, and project_backup—you risk "drift." Drift happens when the code on your laptop is slightly different from the code on your desktop or your team's machines. Without a single, authoritative reference point, you waste time wondering which version is the "real" one.
By using GitHub as your Source of Truth, you move away from tracking files based on their location on your hard drive and instead track them based on the history stored in your repository.
Making GitHub the Master
When you establish a Source of Truth, the repository on GitHub becomes the "gold standard." Your local machine is simply a workspace where you make changes, which you then "push" back to the main repository to update the record.
If you are working on two different computers, the workflow remains identical:
- At the start: You
pullthe latest version from GitHub to ensure your local machine matches the Source of Truth. - During work: You make atomic commits to record your progress.
- At the finish: You
pushyour changes back to GitHub.
By following this, you no longer have to worry about manually copying files between machines. You simply ask Git: "What is the status of the repository on GitHub?"
# Bring your local environment in sync with the Source of Truth
git pull origin main
# ... perform your work and commit ...
# Update the Source of Truth with your new, consistent progress
git push origin main
When everyone on a team (or every machine you own) agrees that the version on GitHub is the only version that matters, you eliminate the confusion caused by duplicate files and outdated local copies. You are now treating your project as a single, unified entity that lives in the cloud, rather than a collection of scattered folders.
Key Takeaway: A Source of Truth ensures that your project remains consistent by making one central repository the only place that defines the current state of your code.