HiWorld
HiWorld

Reputation: 73

How can I add 2 other git repositories as branches for my repo?

I have 3 folders (each a git repo), say Dev UAT and Prototype. I want my Dev branch to be master, and I want those repositories to appear as branches.

So far I was thinking of linking a remote to each folder (with its git inside), and then somehow merge them with the --unrelated tag. How would I do this for 3 branches? I tried but none worked.

To clarify, when I do git branch in the Dev folder, I want to see master Prototype and UAT to apppear as branches. Thanks in advance!

Upvotes: 1

Views: 114

Answers (4)

Michael Durrant
Michael Durrant

Reputation: 96614

Although submodules is the basic answer, I recommend you don't do that because I think you are trying to twist a tool the wrong way.

You want different environments, yes that is common to most shops, including the one I work in and all the others I know.

I recommend you have one master branch and one repository.

When you release different versions you can tag the releases with a version using a common versioning system

Upvotes: 1

Murray Wynnes
Murray Wynnes

Reputation: 303

If you want to add the other repositories as branches in your existing Dev git repo then you can do the following

cd <Dev Path>

git remote add UATremote <Path to UAT Folder Repo>
git fetch UATremote
git checkout -b UAT UATremote/master

git remote add PROTOremote <Path to ProtoType Folder Repo>
git fetch PROTOremote
git checkout -b Prototype PROTOremote/master

And then optionally clean up the remotes:

git remote rm UATremote
git remote rm PROTOremote

Upvotes: 0

e.doroskevic
e.doroskevic

Reputation: 2167

I believe you are describing use of submodules. You use them in scenarioes when you want to keep a repository within another repository. Such requirement may occur when you want to keep a library or an APi you use on a project updated across all contributors.

In order to add a submodule to your current repository use

git submodule add <url>

Where is the URL you grab from GitHub or whatever. Remember submodules are simply repositories so workflow applies... To begin working on your repo within a repo you need to navigate into it like you'd normally do in bash

VERY IMPORTANT

When working with submodules you DO NOT start on a branch automatically. This has to be done manually, so don't forget to do git checkout master when you are in your submodule prior to any work...

Upvotes: 0

CodeWizard
CodeWizard

Reputation: 142652

You simply add new remote

git remote add remote2 <url>

and now you can checkout any branch form any given remote to your repository.

Upvotes: 0

Related Questions