# Tip of the day: How to sync your pull request branch with the master branch

**URL:** <https://discourse.itk.org/t/tip-of-the-day-how-to-sync-your-pull-request-branch-with-the-master-branch/6491>\
**Category:** Engineering\
**Tags:** git\
**Created:** [March 4, 2024, 4:58pm UTC](https://discourse.itk.org/t/tip-of-the-day-how-to-sync-your-pull-request-branch-with-the-master-branch/6491 "2024-03-04T16:58:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)\
**Post date:** [March 4, 2024, 4:58pm UTC](https://discourse.itk.org/t/tip-of-the-day-how-to-sync-your-pull-request-branch-with-the-master-branch/6491/1 "2024-03-04T16:58:50Z")

</div>

Before pushing a local branch, it’s usually recommended to synchronize the branch with the latest revision of the main branch (the `master` branch, in the ITK git). While working on my local feature-branch, I often found myself doing:

1. checkout the master branch
2. pull ITK from the upstream (`github.com/InsightSoftwareConsortium`)
3. checkout my feature-branch again
4. open a Git Bash prompt, and do `git rebase master`

Are other developers here also used to this rather clumpy procedure? Baldur, a colleague of mine at the [LUMC](https://www.lumc.nl) pointed me at this acticle: [How to git rebase on main without switching branches - Geoff Rich](https://geoffrich.net/posts/git-rebase-with-latest-changes/)

It appears that we can just do (while keeping our feature-branch checked-out):

```auto
git fetch upstream master:master
git rebase master

```

So there is no need to checkout back and forth!

Hope this may be of help to you as well!

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [March 4, 2024, 7:44pm UTC](https://discourse.itk.org/t/tip-of-the-day-how-to-sync-your-pull-request-branch-with-the-master-branch/6491/2 "2024-03-04T19:44:44Z")

</div>

I am not restricted to a Linux console frequently enough to remember these commands by heart. And as someone who principally uses very visual TortoiseGit: TortoiseGit makes rebasing easy!

---

<div class="post-metadata">

**Author:** ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)\
**Post date:** [March 5, 2024, 8:19am UTC](https://discourse.itk.org/t/tip-of-the-day-how-to-sync-your-pull-request-branch-with-the-master-branch/6491/3 "2024-03-05T08:19:02Z")

</div>

> [@dzenanz](#):
>
> TortoiseGit makes rebasing easy!

Thanks @dzenanz I also use TortoiseGit. But then, how do you locally synchronism your feature branch with the master, when your local master is also outdated? Do you do

TortoiseGit ==\> `Switch/Checkout...` Branch `master`  
TortoiseGit ==\> `Pull...`  
TortoiseGit ==\> `Switch/Checkout...` Branch `your-feature-branch`

? Or do you do it more cleverly?

The nice thing about `git fetch upstream master:master` is that it allows skipping those back-and-forth checkouts.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [March 5, 2024, 2:09pm UTC](https://discourse.itk.org/t/tip-of-the-day-how-to-sync-your-pull-request-branch-with-the-master-branch/6491/4 "2024-03-05T14:09:05Z")

</div>

I use `fetch` a lot, and I almost never do `pull`. After a `fetch`, I can visually see all the branches:

 ![Screenshot 2024-03-05 09.05.57](https://discourse.itk.org/uploads/default/original/2X/0/051e75a462a700d62a647e4be334b960c3145a54.png)  
Then I decide whether to `rebase` on master or `cherry pick` some commits.
