Updated: 24.02.2023
When you forked a repo then your copy of forked-repo in your Github profile will be referred to as origin while upstream refers to the real origin where the repo was forked from. If you cloned a repo then you will have local copy of the origin repo. You can read here to convert it as a forked repo.
Use this command to see the origin of the repo or its upstream if it’s added.
git remote -v
To sync your forked repo then you have to add the upstream url.
git remote add upstream https://github.com/repo-name.git
git fetch upstream
git checkout master
git merge upstream/master
If you want to see the changes from upstream before merging to master, you can use one of these
alternatives. Specifying git log -10
will show the last 10 commits.
git diff master upstream/master
# OR
git diff ..upstream/master
git log --oneline --graph -10
git log --since=2.day
git show
If you have error for displaying the diff
you might have to specify editor with -git config --global
core.editor emacs
. In this case I use emacs as my diff editor.
When everything is updated without conflict then you can push to your origin. Sometime you get error when pushing to origin because your local copy have different HEAD from the origin. You could force push with
git push -f origin master