Joy
Joy

Reputation: 4483

How to update a branch after checking out

I am new to Git. I have checked out a branch X from Y. Actually I forgot to do "git pull origin Y" before creating the new branch. Later I checked out to Y and did "git pull origin Y". I want to know how do I get those changes in Y to my branch X that I have cut from Y. Thanks in advance

Upvotes: 1

Views: 118

Answers (2)

VonC
VonC

Reputation: 1324198

Rather than merging the two branches, especially if you don't have pushed X yet, I would rather rebase X on top of Y.

You started from:

y--y--y         (branch Y)
       \
        x--x--x (branch X)

You belatedly did the git pull Y to update Y:

y--y--y--y--y   (branch Y)
       \
        x--x--x (branch X)

So simply rebase X on top of the updated Y:

git checkout X
git rebase Y

y--y--y--y--y   (branch Y)
             \
              x'--x'--x' (branch X)

See "git rebase vs git merge" for more.

Upvotes: 2

umläute
umläute

Reputation: 31284

simply merge the two branches:

 # make sure we are on branch master
 git checkout master
 # merge branch Y from origin into master
 git merge origin/Y

Upvotes: 0

Related Questions