0

I need to merge a branch from a different repository (project1) to my current empty repository, therefore I was using the command: git merge --allow-unrelated-histories project1/<branch name>

project1 has 3 branches:

remotes/origin/feature/add-logging
remotes/origin/feature/create-awesome
remotes/origin/master

When the branch's name is feature/add-logging so the command is: git merge --allow-unrelated-histories project1/feature/add-logging

Then GIT said: merge: project1/feature/add-logging - not something we can merge

I think the problem is the slash in the branch name because I can successfully merge the branch master with the command git merge --allow-unrelated-histories project1/master

How could I fix this? Thank you so much

mylearning
  • 65
  • 6

2 Answers2

1

project1/master refers to the branch master of the remote named project1.

But in your case, you have fetched the only local branch of project1: master.

The other branches from project1 are remote tracking branches (origin/xxx), tracking the remote "origin" from which project1 was initially cloned.

You need to make those tracking branches as local branch in project1 first, before a fetch from project1 in your current repo allows you to merge project1/anyBranch.

See "Track all remote git branches as local branches", to be done in project1, before fetching (again) project1 in your repository.
Then, in said repository, you will be able to merge any project/xxx you want.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

That can't be the problem:

$ git log -5 --pretty='git branch test/%h %h' | sh -x
+ git branch test/20ae7113be 20ae7113be                   
+ git branch test/9b09ab0cd7 9b09ab0cd7           
+ git branch test/225bc32a98 225bc32a98                                                                                
+ git branch test/b06a5047ee b06a5047ee
+ git branch test/f7cd3c0832 f7cd3c0832
$ git clone -ns . `mktemp -d`
[…]
$ cd $_
$ git checkout test/f7cd3c0832
[…]
$ git merge origin/test/20ae7
merge: origin/test/20ae7 - not something we can merge                                                                  
$ git merge origin/test/20ae7113be
[… the usual merge output, it works …]
$

So I think you typo'd your branch name.

jthill
  • 55,082
  • 5
  • 77
  • 137