Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging changes from master into all branches using Git?

Tags:

git

branch

merge

I use git to maintain multiple working copies of my code. The idea is that I can check out any branch, build and run it to see how the branch's feature x fits in with the current state of the code.

Git's master branch is the Trunk and the other git branches are features or things I would like to try out. Therefore, my typical usage is updating the master with the latest fixes and then merging master into the individual branches so each of them stays up to date.

This system works well for me, except for the fact that I have to checkout a branch, merge the master and rinse/repeat for the other branches. Given a version control system like git, I don't see this scaling very well given the fact that I'd be prone to spawning a lot of branches over time.

I'm still a git beginner, so I suspect there may be a mechanism of sorts that git already has that I might be missing. Is there one? If not, how does one commit a change to all branches so they stay up to date on their own?

like image 470
Carl Avatar asked Feb 24 '10 21:02

Carl


1 Answers

If

  1. the branches which you want to merge the latest master commits into are not published AND
  2. you want all commits in master to be in the other branches

then you could simply rebase them onto master after master has been updated. This little script might work if you're using a Unix shell. It rebases each branch onto master.

for BRANCH in `ls .git/refs/heads`; do git rebase master $BRANCH; done
like image 60
Frerich Raabe Avatar answered Oct 24 '22 08:10

Frerich Raabe