0

Say you have a repository with four branches : master,br2,br3,br4. Also say that in your local directory you've cloned only br2, not the master. So,

$git branch
* br2

Now, I want to merge in br2 the branch br3. Here, git clone --single branch won't work, right? Since I except to have, before merge

$git branch
* br2
  br3

I tried the following

$git checkout -b br3 [last commit hash of br3]
fatal: reference is not a tree: 9565138...

How can I do this, i.e. to get br3 in my local repo.

EDIT 1.

$git branch --list --all
*br2
remotes/origin/br2

Also,

$git checkout --track origin/br3
fatal: 'origin/br3' is not a commit and a branch 'br3' cannot be created from it
111
  • 121
  • 6
  • `git checkout -b br3` means you are creating a new branch br3 however you already have it.. – Nesrine Hadj Khelil Dec 06 '20 at 17:43
  • 1
    Does this answer your question? [Git merge two local branches](https://stackoverflow.com/questions/25053697/git-merge-two-local-branches) – flaxel Dec 06 '20 at 17:45
  • 1
    What does `git branch --list --all` say? You might already have `origin/br3` but you might not be aware of it; if you do, the problem is solved. If you don't have it, you can `fetch` it and the problem is solved too. – matt Dec 06 '20 at 17:47
  • Exactly @flaxel `git checkout br3` (without `-b`) then `git merge br2` , I wish this helped you fix the issue @111 – Nesrine Hadj Khelil Dec 06 '20 at 17:53
  • 1
    It's Easy. 1) Go to br2 merge master, Resolved conflict if occur. 2) Go to br3 merge br2, Resolved conflict if occur :) – Ashish Sondagar Dec 06 '20 at 17:58
  • Thanks @matt, the following worked : git fetch origin br3:temp, now I have the branch temp and I can merge or whatever. – 111 Dec 06 '20 at 18:39
  • Yeah, sorry I didn't get it quite right off the top of my head, but this is a standard problem so the duplicate is sufficient. – matt Dec 06 '20 at 19:04

0 Answers0