While using Git/Github, there's a need to be updated with the latest commits.
What is a fork and why is it needed?
Forking a repository means creating your own version of the repo where you can make whatever changes you want. It's like a personal copy. It won't affect the original product. With forks, you can change/modify whatever you want and experiment around code freely and fearlessly! Cool right? Forking has nothing to do with Git, it is a feature of Github. Thanks to this awesome feature otherwise we wouldn't be able to play around with code at such individual levels.
Cloning
In cloning, the copy of the repository is made at your local machine unlike fork where the copy is restricted to a repository on Github only. This is the main difference between fork and clone.
Updating your forked repository
You started contributing to a project so you forked it, began working on an issue. In the mean time, other developers of the project pushed changes to the original repo from where you had forked. Now, you're done working and want to open a PR. When you go on Github, you see
This branch is 5701 commits behind original:master
Now, you need to update your forked repo
(Assuming you've cloned already)
Switching to the master branch
git checkout master
Checking remote versions
git remote -v
Adding/Setting remote
git remote add upstream link
link is of the original repo from where you forked!
upstream is the master branch of the original repo
OR
git remote set-url origin SSH of original repo
Fetching all the changes from the upstream
git fetch upstream
Merging
git merge upstream/master
Finallyy pushing your changes
git push
You're all set to open that PR!
Top comments (3)
Nice one
I would suggest that you update the title of this post to make it clearer what your post is about.
Thanks for the brief. I was also wondering if someone updates his/her repository does it affect your forked version of the same. Now I know better