Easier way to keep a git feature branch up to date

Git

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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.

Solution 3 - Git

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

Solution 4 - Git

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.

Solution 5 - Git

  1. git checkout develop/*
  2. git pull
  3. git checkout feature/*
  4. git merge develop
  5. git push

Solution 6 - Git

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..

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionhafichukView Question on Stackoverflow
Solution 1 - GitWes HardakerView Answer on Stackoverflow
Solution 2 - GitBarney SzabolcsView Answer on Stackoverflow
Solution 3 - GitnomadodaView Answer on Stackoverflow
Solution 4 - Gitthemba alex khumaloView Answer on Stackoverflow
Solution 5 - GitManas Kumar MaharanaView Answer on Stackoverflow
Solution 6 - Gitother Tall guyView Answer on Stackoverflow