How to update or sync a forked repository on GitHub?
This sneppet will guide you on how to update or sync a forked repository on GitHub. Forking a repository is a usual practice in software development process. It allows you to work on a project independently, collaborate with others and you can contribute back to original repository.
What is forking a repository on GitHub ?
When you fork a repository on GitHub, it means you are creating a new repository in your account with a copy of all files and history from the upstream/original repository. You can make your changes to the forked repository by creating new files or modifying existing files without affecting the original repository.
The following section will tell you how to bring your forked repository up-to-date with latest changes from the original/upstream repository. Please note, in order to keep your forked repository in sync with original one, you need to update or sync them periodically.
Update or Sync Forked Repository on GitHub
To update or sync forked repository on GitHub repository, you need to follow the below steps:
1. Fetch the latest changes from the original/ upstream repository by running the following git command.
git fetch <upstream repo>
Replace <upstream repo> with the name of the original repository that you forked from.
2. Checkout your master branch
git checkout master
3. Merge the latest changes from the upstream repository:
git merge <upstream repo>/master
Note, replace <upstream repo> with the name of the original repository.
Alternatively, you can also use git pull to fetch and merge the changes in one step as shown below.
git pull <upstream repo> master
4. Push the updated changes to your forked repository.
git push origin master
Note, make sure to replace origin with the name of your forked repository.
Alternative approach: GitHub’s built-in “Sync” feature
Alternatively, you can use GitHub’s built-in “Sync” feature to update your forked repository. Follow the below steps
- Go to your forked repository on GitHub.
- Click on the “New pull request” button.
- Select the “Sync” option.
- Review the changes and click “Sync” to update your forked repository.
That’s all! Your forked repository should now be completely synced with the latest changes/updates from the upstream repository.
You’ll Also Like
- Throw away the local commits from your branch in Git ?
- Your branch and ‘origin/main’ have diverged, how to fix this ?
- How to connect to Github using SSH ?
- How do you do undo git reset –hard HEAD^ and revert to previous commit ?
- Git – How to compare files in two different branches
- Git not working with a proxy server – gnutls_handshake() failed
- npm ERR! enoent spawn git ENOENT
- GitHub unable to access HTTPS and SSL routines error
- Remove http and https proxy settings of npm and git ?
- Fix Nodejs Error: ENOENT: no such file or directory
- What is the purpose of Git Stash command ?
- Cache https credentials for pushing commits to git repository ?