DEV Community

Eka
Eka

Posted on

Pull (fetch) from a forked GitHub repository

You are working on a project outside of your or your organisation account--an open source project for Hacktoberfest, perhaps. You forked the repo and started working on it.

Meanwhile, the original repo has been updated with new changes. To prevent conflict, you need to pull these changes from the original repo and merge it to your local, forked branch. But wait... how do you do that? ❓🤔

Follow these steps and you'll be good to go. 😎

(1) add remote

git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git

(2) fetch

git fetch upstream

Commits to the remote main branch will be stored in a local branch called upstream/main (same with other branches).

(3) merge to local, then merge to your working branch (if necessary)

git checkout main
git merge upstream/main

# merge to working branch
git checkout eka/working-branch
git merge main

Done!

References

Top comments (0)