I created a fork of another developer’s GitHub project a while back. Since then, the original author has pushed several new commits and features to their main branch. My forked version is now behind and missing these latest updates.
What’s the best way to bring those new changes from the upstream repository into my fork? I want to make sure my copy stays current with the original project without losing any work I might have done on my branch.
To sync your fork with the upstream repository, you should first ensure that the upstream is added as a remote. You can do this using the command git remote add upstream [original-repo-url]. Following that, fetch the latest changes with git fetch upstream. Make sure you are on your main branch by checking out with git checkout main. Finally, merge the updates from the upstream repository using git merge upstream/main. This method preserves your local modifications, ensuring a smooth integration. It’s also advisable to work on separate branches for new features to keep your main branch tidy.