Reputation: 459
I have created new branch from master
and then another branch from new one:
master --> A --> B
Later I found out that some things should be fixed on branch A
, so I went back there and maid those changes. Can I push those changes to branch A
and later merge them with branch B
(I know that I could make those changes on branch B
directly, but I have made a mistake checking out branch A
and now changes are here...) or should I create another branch from branch A
and push those changes to that branch and later merge it with branch B
?
master --> A --> B
|
---> C
If both ways are possible, what would be the difference between them, is one way better then the other?
Upvotes: 1
Views: 191
Reputation: 977
You can make changes in branch A and then rebase branch B. Here is the information on how to rebase : https://git-scm.com/book/en/v2/Git-Branching-Rebasing
Upvotes: 0
Reputation: 11
I am assuming that you have
master
.A
by selecting the master
branch and take checkout using the command git checkout -b A
B
by selecting the A
branch and take checkout using the command git checkout -b B
Later, you want to change the code in branch A. Yes, you can push the changes, to do so, you should select the branch A
by git command git checkout A
. Make the changes and commit in branch A
.
If you want to merge the changes of branch A
in branch B
, follow the steps:
B
using the git command git checkout B
A
using the git command git merge A
You can find the current branch by using the git command git branch
.
Yes, you can use both approaches to achieve your goal
A
and merge with branch B
A
, make the change in a new branch and merge with branch B
.In the 2nd approach, we are unnecessary creating an extra branch from branch A
.
FYI, If you merge branch A
with branch B
, it will not delete the branch A
. Branch A still there unless until you delete the branch by using the git command git branch -d source-branch
.
Upvotes: 1
Reputation: 1327
B
yet, you can simply make the fixes required on branch A
and then merge it to branch B
. This will not show a merge commit as there will be no commits on branch B
to merge. B
, you can either create a temporary branch (eg. C
, hotfix
) from branch A
, then merge it with A
and B
, else you can directly make commits to branch A
then merge with B
.
Both these ways are correct, if the fixes are small, then you can directly commit on A
, else make a new branch and go ahead.Upvotes: 3