-
Notifications
You must be signed in to change notification settings - Fork 7
GIT & GITHUB | Syncing your fork with the original repo using git command line
Note
The SSH
url is used in this tutorial. If you are using HTTPS
url, just replace the SSH
url with the HTTPS
url anywhere git urls are used. What's the difference between SSH
url and HTTPS
url? - See Introduction: using command line git
Open your terminal. In the root of the cloned repo on your computer run the command:
git remote -v
The result will look like this:
origin git@github.com:your-github-user-name-here-instead/the-repo-name.git (fetch)
origin git@github.com:your-github-user-name-here-instead/the-repo-name.git (push)
By default, the word "origin" is used to point to or identify any repo that you own and have access to manage. In the case of forks, you own your fork, and you have access to manage (i.e. push directly to, edit and delete) your fork. The result above also shows fetch and push actions on the origin.
Go to the original @collabo-community GitHub repository that you forked from, get their clone URL, and use it to add another remote called "upstream":
git remote add upstream git@github.com:collabo-community/the-repo-name.git
Run this command again:
git remote -v
The result will look like this:
origin git@github.com:your-github-user-name-here-instead/the-repo-name.git (fetch)
origin git@github.com:your-github-user-name-here-instead/the-repo-name.git (push)
upstream git@github.com:collabo-community/the-repo-name.git (fetch)
upstream git@github.com:collabo-community/the-repo-name.git (push)
By default, the word "upstream" is used to point to or identify any repo that you do not own and do not have access to manage. Simply put, you do not have access to manage (i.e. push directly to, edit and delete) that repo. The result above also shows fetch and push actions on the upstream too.
You are now set and ready pull in changes from the upstream and merge into your origin.
Switch to the develop branch:
git checkout develop
Pull in new changes from the upstream repo to your local computer with:
git pull upstream develop
Sync your fork (check and observe your fork's develop branch on the GitHub web UI after running the command below to see that it's synced):
git push origin develop
Create i.e. checkout to a new branch, make your changes, add, commit and push your new branch.
Tip
Go to your fork on the GitHub web UI, you should see your branch there. Send a pull request as usual.