0

I have a repo called live.git and I have another repo called dev.git.

I want to add the dev.git repo as a branch to live.git so that I can see what's different on dev.git and possibly merge some changes to live.git.

I'm still new to git and I feel like I'm missing something obvious.

I am not looking to keep the history of both repositories, my end goal is to have the differences from dev.git committed to live .git and remove the branch.

Haim
  • 1,107
  • 2
  • 10
  • 19
  • 2
    Possible duplicate of [How do you merge two git repositories?](http://stackoverflow.com/questions/1425892/how-do-you-merge-two-git-repositories) – Avalanche Oct 20 '15 at 14:17
  • 1
    Can you explain the purpose of these two repos? It seems like there should have been one to start with with a dev and live branch. Do they contain the same content? – Captain Man Oct 20 '15 at 14:17
  • we had a live site and a dev site. I just started using git, so i set them both up as a repository. The end result is that i'd like to cherry pick changes from the dev site and push them to the live site. I'm very new at this and scared of doing the wrong thing, so i figured that setting up the dev as a branch of the live would be the better route. thanks for your help. – Haim Oct 20 '15 at 14:41
  • @Haim if you're scared (which is not a bad thing to be for Git), here's some reassurance: as long as your remote source (BitBucket) is up to date and you don't push your changes until you know they are what you want, you can't really go wrong. Worst case you just wipe your local copy and refetch. Git is really forgiving unless you [rewrite history](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History) without knowing what you're doing. – Sam Oct 20 '15 at 15:12
  • @Sam, Thanks. So how should I proceed? – Haim Oct 20 '15 at 15:45

2 Answers2

0

You can't add repositories as branches. To do what you're trying you can add it as a remote.

In live.git do git remote add dev /path/to/dev.git. You'll then be able to do git fetch dev and use git diff to see differences between repos.

Holloway
  • 6,412
  • 1
  • 26
  • 33
0

Assuming you're on your live repo:

# Add dev repo as a remote source
$ git remote add dev git://path/to/dev.git

# Make a new dev branch, on the live repo
$ git checkout -b dev

# Merge in your dev repo using all of "their" code in conflicts
$ git merge dev/master -s theirs

# Commit and compare
$ git commit -am "dev repo merged in"
$ git diff master
Sam
  • 20,096
  • 2
  • 45
  • 71
  • Thanks. my live repo remote source is already set to bitbucket – Haim Oct 20 '15 at 14:50
  • @Haim you can have many remote references. I'm suggesting to add another one, named `dev` for example, that points to the `dev` repo (most likely also hosted on BitBucket). Then you can compare or merge branches from your `dev` remote reference to your `live` repo. – Sam Oct 20 '15 at 15:10