Home > OS >  How to update current branch to the state of master?
How to update current branch to the state of master?

Time:12-09

I'm new to git, so this may have been answered somewhere else, but I honestly don't know how to phrase my search so that it doesn't sound like I just want to push my branch to master.

We have the master branch and two other branches, branches A and B.

I made some changes in branch A and committed them to master.

Now master is identical to my current branch A.

Then my friend, who was working on branch B, makes some changes and commits those to master. We were working on separate files so there are no merge conflicts.

But now my branch A is not the same as master.

How do I get the changes that he made into my branch? I've tried pulling and checking out but Git Bash keeps telling me that branch A is "already up to date." What am I supposed to do here?

Thanks in advance!

CodePudding user response:

Try

git checkout A
git merge origin/master

This is merging the master branch into your feature branch.

In Git, "origin" is a shorthand name for the remote repository that a project was originally cloned from. (from gittower.com)

Another (maybe not so practical) option could be to locally checkout master first and pull:

git checkout master
git pull
git checkout A
git merge master

In this case, you pull (fetch and merge) master from origin. Then your local master is merged into your feature branch.

Many people use rebase to keep the history clean but I usually do not.

A Google search could have been https://www.google.com/search?q=how to merge master into my branch.

CodePudding user response:

Try this

git checkout A
git rebase master

This will make your branch A on the top of master and branch A would have all changes done on master.

Make sure to pull latest branches before doing this

  • Related