Reputation: 164
Currently I'm working in two branches of my project, I started one, but then I needed to create another one to develop another feature. When I finished this last one I merged the branch to master to bring the changes to the production environment.
Now when I switched with phpstorm to the previous one to continue with it, obviously I don't have any of the changes of the second branch which is already merged in the master branch
How can I deal with this situation without losing any of the changes?
Upvotes: 0
Views: 56
Reputation: 72346
The best option (in my opinion) is to rebase your current branch on top of master
. This way it looks like you started working on the current branch after you have merged the first branch into master
(and, of course, the current branch will include all the changes introduced on the first branch).
Before rebasing be sure you don't have uncommitted changes. Either commit them or stash them. This is needed in order to be able to recover if the rebase produces conflicts.
The command is as simple as:
git rebase master
(or you can use the UI provided by PhpStorm for this operation).
Rebasing the working branch on top of master
is better than merging master
into the current branch (which is also a valid approach) because it produces a more linear history that is easier to read.
Upvotes: -1
Reputation: 1759
Merge master into the feature branch which is not up to date with master.
From your feature branch, run:
git merge master
Next, deal with any merge conflicts that occur. After that your feature branch will then be up to date with master.
As a general note, it is worth looking at a some popular workflows such as Gitflow in order to better understand some common ways of managing Git branches.
Upvotes: 2