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?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With