0

Hi Currently I am using git for managing my source code.

I have currently a master branch and develop branch. i usually creates a feature branch from from develop, works on it and then merge back to develop .

How can i get the latest changes on develop branch to other local branches.

in other words if i have two feature branch B1 and B2 both checked from develop . i did some commits on B1 and then merged B1 to develop . How can i get changes from develop branch to my feature branch B2 ?

thank you .

knowledgeseeker
  • 339
  • 4
  • 14

1 Answers1

1

you could merge or rebase.

MERGE

git fetch # make sure origin/develop is up to date
git checkout B2
git merge origin/develop # merge changes from origin/develop into your branch

PRO:

  • you don't need to rewrite your B2 history

CONTRA:

  • you might need to solve conflicts in the merge commit which makes it more difficult to trace changes back, and to know who was responsible.
  • this produces a more complex history

REBASE

git fetch # make sure origin/develop is up to date
git checkout B2
git rebase origin/develop # rebase your B2 branch on the "new" develop branch

PRO:

  • you get a clean "semi-linear" git history
  • all changes are traceable to a single development branch. No merge commit with changes that belong to both features

CONTRA:

  • rewriting history isn't always intuitive
  • you change your history, so if other people work on the same branch, the references change. I consider this ok if I am the only person working on my branch. If other people work on the branch, rewriting history is NOT OK (eg on develop or master branch)
Chris Maes
  • 35,025
  • 12
  • 111
  • 136