# How to keep your fork in sync

**URL:** <https://forum.collaboraonline.com/t/how-to-keep-your-fork-in-sync/49>\
**Category:** Development\
**Tags:** git\
**Created:** [October 20, 2020, 9:07pm UTC](https://forum.collaboraonline.com/t/how-to-keep-your-fork-in-sync/49 "2020-10-20T21:07:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedro.silva](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.collaboraonline.com/pedro.silva/32/4_2.png) [@pedro.silva](https://forum.collaboraonline.com/u/pedro.silva)\
**Post date:** [October 20, 2020, 9:07pm UTC](https://forum.collaboraonline.com/t/how-to-keep-your-fork-in-sync/49/1 "2020-10-20T21:07:59Z")

</div>

# Add a new remote

Give this command only once for each local clone:

```bash
git remote add upstream https://github.com/CollaboraOnline/online.git

```

## Check how many remotes you have (op)

```bash
git remote -vv

```

# Sync your fork

Every time you want to sync your fork with the original repo:

- `git fetch upstream`
- `git checkout master`
- `git pull upstream master`
  - Or if your master branch had dirty tree `git pull upstream main --rebase` but probably then you will need to resolve conflicts between forked master and upstream master. Better to always work in another branch. See [Your First Pull Request (forked repository)](https://forum.collaboraonline.com/t/your-first-pull-request/41#if-you-are-not-part-of-the-organization-over-at-gh-probably-the-most-common-1)

- `git push`
  - Or in the case your forked master branch is polluted with something **and already pushed** , better to remove those commits via `git rebase --interactive HEAD~6` (gives you the power to change the history for the last 6 commits) and then after that is solved: `git push origin master --force`

# Bonus

Probably best to don’t allow merge commits to get into your forked repository history. You can do that by going to GitHub forked repository → settings (cog wheel) → ctrl + f for merge and change those options to:

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/collaboraonline/original/1X/bf210fea765a4344157912ec707c31e3334433db.png)

---

<div class="post-metadata">

**Author:** ![pedro.silva](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.collaboraonline.com/pedro.silva/32/4_2.png) [@pedro.silva](https://forum.collaboraonline.com/u/pedro.silva)\
**Post date:** [August 3, 2022, 9:48am UTC](https://forum.collaboraonline.com/t/how-to-keep-your-fork-in-sync/49/2 "2022-08-03T09:48:25Z")

</div>

I have changed this to a wiki post
