You may have noticed something while watching the previous videos...Do you have to always fork the Open Source project every time master get's updated? What happens if somebody makes an update to the original project and now your forked project is out of sync and outdated? Luckily for you, there is an easy way to always make sure your fork has the most up to date version of the original project. Here is how:
Once you are in your forked project directory in your command prompt....
Type git remote -v
and press Enter. You'll see the current configured remote repository for your fork.
git remote -v origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch) origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
Type git remote add upstream
, and then paste the URL you would copy from the original repository if you were to do a git clone. Press Enter. It will look like this:
git remote add upstream https://github.com/zero-to-mastery/PROJECT_NAME.git
To verify the new upstream repository you've specified for your fork, type git remote -v
again. You should see the URL for your fork as origin
, and the URL for the original repository as upstream
.
git remote -v origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch) origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push) upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch) upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)
Now, you can keep your fork synced with the upstream repository with a few Git commands.
One simple way is to do the below command from the master of your forked repository:
git pull upstream master
Or you can follow along another method here: "Syncing a fork."