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
            Asked
            
        
        
            Active
            
        
            Viewed 77 times
        
    2 Answers
2
            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.
0
            
            
        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
 
    
    
        umläute
        
- 28,885
- 9
- 68
- 122
- 
                    So you mean here I should do "git checkout X" and then "git merge Y" to get the changes in Y to X, right? – Joy Oct 21 '13 at 10:10
- 
                    @Joy, since you have created your `Y` branch all by itself, you most likely have two different branches `Y` and `origin/Y`; that's why i say that you should do `git merge origin/Y` rather than `git merge Y`. – umläute Oct 21 '13 at 10:11
- 
                    @Joy: also you don't need to `git checkout master` if you are already on *master* branch. – umläute Oct 21 '13 at 10:12
 
     
    