How to update a fork with git rebase

Marcos Marcolin • June 24, 2024 • 1 min read

git github

How to update a fork with git rebase

What is a Fork?

A fork is a copy of a repository, letting you make changes to the code independently. On GitHub, forking a repository is common practice for collaborating on open source projects. After making changes, you can send a pull request so your changes can be reviewed and merged into the original project.

Updating your Fork

To keep your fork up to date with the original repository, you can use git rebase.

Here's a step-by-step guide to update your fork:

1: Add the remote repository you forked and name it upstream:

git remote add upstream https://github.com/original-repository/here.git

2: Fetch all branches from the upstream remote repository

git fetch upstream

3: Rewrite your master branch on top of upstream's master using git rebase

git rebase upstream/master

4: Push your updates to your fork's master branch. You may need to force the push using --force

git push origin master --force

Conclusion

Keeping your fork up to date with the original repository is crucial for effective collaboration. Using git rebase ensures your fork stays aligned with the latest changes, making it easier to merge in new features and minimizing conflicts.

Share: