1

Let's say I have project on c:/project/project1 and c:/project/project2

And then I create another project c:/project/project3

Assume short form of the word
BR = Branch
RB = Rebase
CP = Copy
[All word & letter inside this [] refer to branch name]

Let say project1 has the following commit that has been rebase

INIT--p11---------------------RB BR A--[MASTER]
     \--p12--p13--p14 [BR A] /       \--p15-- [BR B]

And Let say project2 has the following commit that has been rebase

INIT--p20--------------------RB BR C-----------------RB BR D--p24--[MASTER]
         \--p21--p22 [BR C] /       \--p23-- [BR D] /

My question is:

How do I copy the repository on BR A and BR D only or maybe with some commit p24 to project3 with their files (changed / newly created)

The way I hope in project3, the copy branch from another repository should not go to master but on individual branch, then later on to be merge with master and rebasing. I illustrate the structure above on project3

INIT-----------------------------RB BR A--p31--p32--RB BR D--p24--[MASTER]
    \--p12--p13--p14 [CP BR A]--/                  /
     \--p23 [CP BR D]-----------------------------/

I've see guide on how to copy/move/clone repository to another from remote/online repo. But I don't found any relate to local repo.

halfer
  • 19,824
  • 17
  • 99
  • 186
khai
  • 75
  • 7
  • You are at the local master branch(master) when you rebase the branch (lets say BR A)?? One more question where did you rebase the BR B? Sorry I just want to understand your question. – Subrato Pattanaik Jan 02 '21 at 05:06
  • Generally, you init project3, add project1 and 2 remotes, and then merge, cherry-pick, and rebase as you need. However, you're explaining how you'd like to solve your problem. What are you trying to solve? How are projects 1, 2 and 3 related? – Schwern Jan 02 '21 at 05:40

1 Answers1

0

Project 1 Case

Initially, you have clone one project in this c:/project/project1 directory. At this stage when you do git status it will show that you are on branch master and your branch is up to date with origin/master.

Now according to your setup, BR A is a branch that keeps track of origin/master and it has 5 commits(in your case) which means that BR A is 5 commits ahead of origin master. Git will suggest that you need to push this branch to origin/master in order to have a remote repository up-to date.

Here you need to understand one situation, in your local repo you will have two branches one is master and another is BR A. You are on Br A that keeps track of origin/master. As branch A has 5 commits ahead of origin/master so you will push it in the remote repository.

After pushing it into the remote repository git push origin branchA, in your remote repository you will have two branches one branchA and master.

Branch tree in remote
 |--- branchA (5 commits ahead)
 |--- master
Branch tree in local
 |--- branchA (5 commits ahead)
 |--- master

As per your setup, you are at the local master branch and you have rebased the local branch BR A into your master branch git rebase branchA. After you did rebase,

Branch tree in local
 |--- branchA (0 commits ahead)
 |--- master(5 commits ahead of origin/master)

If you want to update your remote master branch then you will do a pull request and once it is approved you will merge it.

Branch tree in remote
 |--- master (up to date)
 |--- branchA (0 commits ahead)

Now here local remote will looks like this

Branch tree in local
 |--- branchA (0 commits ahead)
 |--- master(5 commits ahead of origin/master)

Now you will do git fetch then your local will looks exactly the same as the remote repository.

Branch tree in local
 |--- master (up to date)
 |--- branchA (0 commits ahead)

Project 2 Case

Similarly, you have initially clone another project in this c:/project/project2 directory. You did the same exact setup which you did for project 1 but this time you have branchC and branchD. After rebasing process in the local and merging process in the remote,

Branch tree in local
 |--- master (up to date)
 |--- branchD (0 commits behind)
 |--- branchC (0 commits behind)

Now finally the question is you want to have branchA (which is master branch of project 1 actually) and branchB(master branch of project 2) into your third repository locally.

Don't create another repository just merge one repository with another repository.

For that, this answer would help you to achieve what you really want.

Subrato Pattanaik
  • 5,331
  • 6
  • 21
  • 52