Easy Guide: Keep Two Git Projects in Sync
Imagine you have one project you follow (the “source”) and another project where you want to save a copy (the “mirror”). Just run these simple commands—no technical background needed.
1. Open Your Project Folder
On your computer, go to the folder where your source project lives. If you haven’t downloaded it yet, do this once:
git clone <SOURCE_ADDRESS> my-project
cd my-project
If you already have it, skip cloning and just enter your folder:
cd path/to/my-project
2. Tell Git About Both Projects
By default, Git knows about the source project only. Rename that connection to “source” and add your mirror project as “mirror”:
git remote rename origin source
git remote add mirror <MIRROR_ADDRESS>
3. Get the Latest Changes from Source
Always grab new updates first:
git pull source main
(“main” is the common name for the main branch. If yours is “master,” use that instead.)
4. Send Those Updates to Your Mirror
Now push everything you’ve just pulled into your mirror project:
git push mirror main
5. One‑Click Sync (Optional)
Make a tiny script so you don’t have to type both commands every time. Create a file named sync.sh
with these lines:
#!/bin/bash
git pull source main
git push mirror main
echo "All done!"
Then run:
chmod +x sync.sh
./sync.sh
What’s Happening?
- git pull source: Downloads the newest version of the source project.
- git push mirror: Uploads that version into your mirror project.
Comments
Post a Comment