GIT - "import" content from another branch

Asked

Viewed 1,100 times

3

My question is this::

I have a repository called "site-layout" with only the master branch, where I develop a layout with bootstrap v4.

I still have another repository called "site-old" also only with the master branch, where is the code of another layout but created with bootstrap v3.

What I would like to do is "import" (I don’t know if that would be the correct term) this "site-old" into the "site-layout" as a new branch that I want to call "bootstrapv3" (and then delete the "site-old", and then, if possible, "mirror" this branch into the "site-layout master".

EDIT: If it gets too complicated (it’s even better), it could just be "mirror" the content of the "old site" right into the master of the "site-layout", as long as it doesn’t interfere with the Fork that I’ve created based on the content of the current master.

Finally, to illustrate, the structure of both repositories is like this:

site-layout (ou site-old)
|
+--- master

And how I’d like to organize:

site-layout
|
+---master ("transferir" o conteúdo daqui pra bootstrapv4, e depois passar pra cá o conteúdo da bootstrapv3 (ou site-old))
+--- bootstrapv3 (com o conteudo vindo da antiga site-old)
+--- bootstrapv4 (com o conteúdo vindo da master do site-layout)

Grateful from now on!

  • 1

    Do you have any intention of merging these two branches at some point?

  • No. The only thing I could intend to do is to put the content of each of the two branches in the master (I don’t really know if I can do this), like, when I was developing pro bootstrap v3 I would use it as master, and possibly later bootstrap v4. If that’s not possible, quiet.

  • I have the impression that you did not understand the function of the master branch, it is the main one of the repository, not the "working branch". Because it makes no sense to transfer one branch after the other to the master, which you will not do merge. From the scenario described it is better that your repository does not have a master, you can configure which branch will be the main one directly from github.

2 answers

2

If the modification between what you have in one repository for the other is completely different it makes no sense to keep in the same.

If upgrading bootstrap v3 to v4 is partial, it makes sense to keep it in the same repository. In this case I think that creating a branch and copying and pasting the files and deleting the ones that will no longer be used is the easiest way.

//site-old
git checkout master
git checkout -b bootstrapv3
git checkout master
git checkout -b bootstrapv4
//Copie e cole todos os arquivos do repositório site-layout que são diferentes.
git add -A
git commit -am "Adição inicial de bootstrapV4"
git push origin //para criar as branches no repositório remote.

Now you can work on both versions independently.

In this case you will have two Masters and the master branch will no longer be used or will be used to replicate one of the two versions only.

NOTE: The master branch is just a standard used in the initial generation of git repositories. But git itself has no preference for any branch. So having a main branch that is not the master or having more than one main branch for different versions of the code is not wrong.

  • Oh gee, and there’s no way to preserve the commits? And I thought to move from site-old to site-layout, and not the other way around (bootstrapv4 files are already on site-layout, which is the repository to be maintained.

  • If one was born from the arches of the other VC may try to add a second remote to the new repository. Maybe you can keep commits using rebase from there.

  • Yeah, since I’m completely GIT layman, I’m not sure what the commands are. Anyway, I gave up on this import (and the question) and now I’m using only the old repository as a developer. I don’t know how the stack system works in such a case, but if I can I validate your answer.

  • If you consider that is a possible answer to your question, but that has not solved your problem can give an up vote. If it would solve your problem you can mark as answer =).

1

To "transfer" the branches simply rename. To import another repository as a branch, add the remote repository, do checkout and delete the remote:

# renomeia master (atual) para bootstrapv4
git branch -m bootstrapv4

# adicionar repositório remoto e importar como ramificação
git remote add site-old [email protected]:seu-usuario/site-old.git
git remote update site-old
git checkout -b bootstrapv3 site-old/master
git remote remove site-old

As I indicated in the question comment, it’s best that your project doesn’t have the master branch, set up the main branch on github.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.