1

I am on a repo on github. I have one local branch called : master and on the remote repo there are two branches, branch1 and branch2. I cloned the repo from the branch1. But then, I wanted to pull branch2, which is quite different from branch1, into master. So I did : git pull origin master:branche2

But when I run a git diff command between master and the new local branch2, I have no differences. Does this mean that there was no merging, and that the former master has been totally replaced by the imported branch2 ?

user1611830
  • 4,749
  • 10
  • 52
  • 89
  • if you do: git log --oneline --decorate --graph --all .. do you see both branches ?? and: where does your master point to? branch1 or branch2? – Stephan Oct 01 '12 at 12:46
  • @stephan I have this : * 1441dce (HEAD, origin/master, origin/HEAD, master, branche-0110). How do I checke where the master points to ? – user1611830 Oct 01 '12 at 13:05
  • 1441dce -> this is the hash or identifier of your current/last commit and everything behind that in the brackets are pointers to this commit - so your master is in sync with origin/master and also pointing to branche-0110 - the question is, where your second branch is.. is it within one line with the master? if yes the changes are also in your working dir.. if not then you will have to merge/rebase – Stephan Oct 01 '12 at 13:17
  • @Stephan, What I named the second branch is the remote branch-0110. What do you mean by being inline with the master ? When I run in local git branch, I have two local branches : master and branch-0110. So I really don't understand what is going on – user1611830 Oct 01 '12 at 13:24
  • 1
    it is realy hard to explain the important concepts of git in 500 chars :-) ... but if you branch1 in your question is the master in your repository and branch2 in your question is branch-0110 then your repo should be up to date and branch2 points to the same commit (is at the same state as branch1) - you see that from the line you posted {* 1441dce (HEAD, origin/master, origin/HEAD, master, branche-0110)} - it seems that everything was merged... but its hard to say what realy happend without further info.. – Stephan Oct 01 '12 at 13:30
  • maybe you can take a look at this (and also the other stuff on this site): http://think-like-a-git.net/sections/graphs-and-git.html – Stephan Oct 01 '12 at 13:38
  • @Stephan, Ok, in fact what I called branch1 in the remote was indeed master. But what I don't understand is why I didn't have any merge or any info in my local master ? I had just a message when pulling : From github.com:my_repo * [new branch] master -> branch2 Already up-to-date. – user1611830 Oct 01 '12 at 13:38
  • 1
    http://stackoverflow.com/questions/634546/git-merge-mystery -> The message “Already up-to-date” means that all the changes from the branch you’re trying to merge have already been merged to the branch you’re currently on ....-> does this help? – Stephan Oct 01 '12 at 13:46
  • Thanks Stephan, but it is quite a mystery ...:) – user1611830 Oct 01 '12 at 14:06
  • I agree .. the git learning curve is very hard.. but if your used to it you wouldn't wanna miss it for the world :-P just keep on trying.. it WILL get easier.. ;-) – Stephan Oct 01 '12 at 14:10

2 Answers2

0

Do the following:

git branch branch2
git checkout branch2
git pull origin branch2
git checkout master
git merge branch2
Christoffer Hammarström
  • 27,242
  • 4
  • 49
  • 58
Marko Novakovic
  • 470
  • 2
  • 10
0

In git if you need to change from one branch to another the you need to do:

git checkout branch_name

example: Just change to the branch you want as a base:

example: git checkout branch1

if you are on branch1 and want to merge branch2 on to branch1 then:

git merge origin/branch2

Now you have the differences on branch2 merged on to branch1.

slash28cu
  • 1,614
  • 11
  • 23