Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+3 votes
2 views
in DevOps and Agile by (29.3k points)
edited by

I'm new to Git, and now I'm in this situation:

I have four branches (master, b1, b2, and b3).

After I worked on b1-b3, I realized I have something to change on branch master that should be in all other branches.

I changed what I needed in master and... here is my problem:

How do I update all other branches with master branch code?

2 Answers

+3 votes
by (50.2k points)
edited by

You have two ways to resolve this problem 

Use Merge, but it creates an extra commit for merge

Alternatively, you can do a rebase.

Let’s see how this can be done: 

Checkout each branch:

git checkout b1

Then merge:

git merge origin/master

Then push:

git push origin b1

With rebase use the following commands:

git fetch

git rebase origin/master

Thus, you can update your git branch from the master. Here is an excellent tutorial for git please go through this link and you will get your basics of git more clear.

 

Update Git branches from master -git update branch from master
Intellipaat-community
by (19.4k points)
it would be better if you use rebase rather than merge.
0 votes
by (36.7k points)

In this case, you need to perform a git merge.
A Git merge combines the histories of two branches, ensuring that the updates from the master are reflected in your other branches.

In your case, using Git merge, you will be able to integrate changes from the master branch into your other branches (b1, b2, b3).

Steps:

  • Switch to Branch b1:

git checkout b1

  • Merge Master into b1:

git merge master

If there are conflicts, resolve them, then commit the changes.

  • Repeat Steps 1-3 for b2 and b3:

Switch to branch b2, merge master, and resolve conflicts.

Do the same for other branches

...