Dawood Zaidi
Dawood Zaidi

Reputation: 288

Git Recent pull to a branch

Let's say I'm working on a branch XYZ and someone else pushes some changes in the main branch, How do I get the latest changes to my branch XYZ? I switched to dev branch and got the latest pull but when I go back to my branch XYZ I don't get the recent changes that I get in the Dev branch.

Upvotes: 2

Views: 119

Answers (4)

Croolman
Croolman

Reputation: 1123

It is possible to do so even without switching branches. Switching is slow if there are a lot of new changes on dev. Be careful though - with this process you have to be sure you pushed all the local hanges you previously made on dev.

# get latest commit from dev branch whilst still being on XYZ
git fetch origin dev:dev
# merge those changes
git merge dev

Upvotes: 0

Mukesh A
Mukesh A

Reputation: 323

You have to merge your dev branch into your branch XYZ like this:

git checkout dev
git pull origin dev
# to get your branch up to date with the remote

git checkout XYZ
git pull origin XYZ
# to get your branch up to date with the remote

git merge dev 
# this will merge your dev branch into your branch XYZ.
# there could be possible "merge conflicts" resolve it.

Upvotes: 0

You'll have to do this

git checkout xyz

git pull origin xyz
git merge main_branch

Upvotes: 0

VonC
VonC

Reputation: 1329592

If you have not pushed yet your branch XYZ, assuming that XYZ was created from dev:

git checkout dev
git pull
git checkout XYZ
git rebase dev

That will replay your local commits on top of the updated dev.

If XYZ was alreay pushed, then it is more prudent to do a simple merge.

git checkout XYZ
git merge dev

Upvotes: 5

Related Questions