katie hudson
katie hudson

Reputation: 2893

Keeping changes across branches

I am pretty new to Git and think I have managed to get myself a bit lost.

So I get a Jira task, and from that I create a branch like so

git branch J12345-123
git checkout J12345-123

I then work on the branch, and when ready commit and push

git add .
git commit -m "Some message"
git push

Sometimes the push ask me to set upstream, not too sure what this is? e.g.

git push --set-upstream origin J12345-123

Anyways, once everything is done on this branch, I merge it with the master branch.

The issue I am facing is this. I created a new branch and was working on it (lets call it Branch A). I then had the need to create and work on another branch (Branch B) before I had finished my work on Branch A. As such, I committed and pushed my changes for Branch A. I did not merge with master as I am not finished on this branch.

From Branch A, I then created Branch B and this included the modifications I had made in Branch A (which is what I wanted). I then worked on Branch B, committed and pushed it. I then merged Branch B with master.

Now, I go back to Branch A, and none of the work I done on Branch B is there. I want what I did on Branch B to now be present on Branch A.

How can I achieve this?

Thanks

Upvotes: 1

Views: 61

Answers (1)

VonC
VonC

Reputation: 1324935

Simply merge B to A:

git checkout A
git merge B

Since you have created B from A, the merge will be a trivial fast-forward one.
Assuming you did not make any commit on A since you switch to B.

a--a        (A)
    \
     b--b   (B)
         \
          M (master)

Merging B to A means A HEAD will move to B

a--a        
    \
     b--b   (A, B)
         \
          M (master)

Upvotes: 4

Related Questions