To update or sync a forked repository on GitHub with the changes from the original repository, you need to perform a few steps. Here's an example:
Let's say you have forked a repository called "original-repo" and want to update your fork with changes from the original repository's "main" branch.
Clone Your Fork: Clone your forked repository to your local machine using the following command. Replace
<your-username>
with your GitHub username.sh
git clone https://github.com/<your-username>/original-repo.git
cd original-repo
Add Upstream Remote: Add the original repository as an upstream remote. This allows you to fetch changes from the original repository.
sh
git remote add upstream https://github.com/original-owner/original-repo.git
Fetch Changes from Upstream: Fetch the changes from the upstream remote.
sh
git fetch upstream
Merge Changes: You can choose to merge the changes from the upstream repository's branch into your local branch. For example, to merge changes from the "main" branch of the upstream repository:
sh
git checkout main git merge upstream/main
Alternatively, you can rebase your local branch onto the upstream branch:
sh
git checkout main git rebase upstream/main
Push Changes to Your Fork: Once you've merged or rebased the changes, push the updated branch to your forked repository on GitHub.
sh
git push origin main
Create a Pull Request (Optional): If you've made changes to your fork and want to contribute back to the original repository, you can create a pull request from your fork's branch to the original repository's branch.
By following these steps, you'll keep your forked repository updated with changes from the original repository. Remember that you might need to adapt the branch names (e.g., "main") to match the repository's specific branch naming convention.
Comments
Post a Comment