Easier Way to Keep a Git Feature Branch up to Date

I was wondering if anyone would have a better suggestion for keeping a feature branch in sync with it's parent branch.

We typically have multiple feature branches that are being worked on at a time, each derived from our develop branch. It's fairly common for feature branches to be merged into develop a couple times a day.

In order to stay on top of changes (i.e. resolve conflicts) I find I need to keep the feature branches I'm actively working on up to date with develop.

To do this I run these commands a couple times a day:

git checkout develop
git pull
git checkout feature/foo 
git merge develop 
git push

The last git push I usually only do if I'm working with someone else on the feature branch.

Is there a better or more convenient way to do this?

0

6 Answers

Well, git is really set up for wrapping things you do frequently into a script and then calling the script instead. There isn't a huge number of variations on the above. They all will require pulling the upstream branch, and then integrating your changes with the upstream's. Some things that may shorten it for you might be:

git checkout feature/foo
git pull --all
git rebase develop

That way you can simply pull all the upstream branches in one shot without switching to the other branch. And rebasing is possibly an operation you may prefer over merging, but that's frequently a personal choice depending on how you want the history to look.

6

Why not make a script that would run the commands?

Create merge-develop.sh with text

#!/bin/bash
git checkout develop
git pull
git checkout feature/$1
git merge develop 
git push

Then simply run merge-develop.sh foo.

Another option is to fetch with target, which allows you to pull develop without checkout:

git checkout feature/foo
git fetch origin develop:develop
git rebase develop

What I find so easy to use is this


 1. git checkout develop
 2. git pull
 3. git checkout -b feature/foo
 4. git push

Number 3 creates the new branch from develop and then checkout to it... all in one line. I personally prefer this.

1
  1. git checkout develop/*
  2. git pull
  3. git checkout feature/*
  4. git merge develop
  5. git push
git checkout develop
git pull origin develop
git merge --no-edit ${FEATURE_BRANCH}
git push origin develop
git checkout ${FEATURE_BRANCH}

this worked for me..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest