Reputation: 612
Recently we started using Gitflow for our projects and we are experiencing some problems we cannot wrap our head around.
We have the default setup with the master
, develop
, feature/xyz
and hotfix
branches. So assume I am working on a long term feature, let's call this feature/long-time
. My colleagues are in the mean time working on feature/short-time
. Imagine that after some work, they will commit feature/short-time
in to develop
and I occasionally commit feature/long-term
so they can see my progress and it is safely backed up.
Naturally, the feature/long-term
cannot ignore the develop
branch for too long or it will fall behind. So how can we periodically sync the changes to the develop
branch to the feature/long-term
branch?
I have come across two options:
git merge
every now and then. However, I feel like this is not really correct according to Gitflow's philosophygit rebase
a few times now too, however this seems to work only if you do not push your changes to the remote branch, is that correct?To wrap up: how do I correctly keep my feature branche(s) up to date?
Upvotes: 4
Views: 3202
Reputation: 1794
This brings back again the merge vs rebase discussion, which has been tackled multiple times. For a long story, you can check here.
As you correctly said, it is not good to rebase if you're pushing your branch, as changing your git history would make you force the push, which is not good for a daily basis, but rebasing in general is "cleaner" than a merge, so:
merge
. rebase
is a better option. In the case that you are working in a very long task, even if rebase is your main strategy, merging from time to time is a good idea because:
1. Your changes are backed up in the remote repository from time to time.
2. It is not practical to rebase a big number of commits, as the diff is calculated commit by commit, whilst in a merge it is calculated for all the commits at the same time. This means that for a large number of commits you might need to resolve an unnecessary big amount of conflicts that can be reduced to one per file with a merge.
To sum up, I would suggest rebasing most of the times to keep a clean repository, but merging from time to time to keep a backup of your branch in the repo and lighting future rebases.
Upvotes: 4