Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easier way to keep a git feature branch up to date

Tags:

git

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?

like image 802
hafichuk Avatar asked Mar 06 '12 16:03

hafichuk


People also ask

How do I update a feature branch in GitHub?

In GitHub Desktop, use the Current Branch drop-down, and select the local branch you want to update. To pull any commits from the remote branch, click Pull origin or Pull origin with rebase. Resolve any merge conflicts in your preferred way, using a text editor, the command line, or another tool.


3 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 fetch --all
git merge --into-name=develop origin/develop
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.

like image 50
Wes Hardaker Avatar answered Oct 26 '22 14:10

Wes Hardaker


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.

like image 32
Barney Szabolcs Avatar answered Oct 26 '22 14:10

Barney Szabolcs


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
like image 39
nomadoda Avatar answered Oct 26 '22 14:10

nomadoda