0

If this is a stupid question please kick me, but I need to crowdsource experience.

I have code on two different servers - that are basically production and dev sources of the same application, but are not exactly the same and don't have the same history - that I inherited from someone whose coding standards/practices are basically non-existent. I have created a Git repository for the production code (master branch) and uploaded everything. Happy days, great times, everything's good.

Now I want to add the dev code (from the dev server) into the same repository, but as a separate branch. I've read up on git checkout --orphan <branch>, and it seems like this might be the option for me but I'm unsure. Do I add the remote of the current repo (with the master branch already committed, updated, etc.) to the "new" git repo I initialized on the dev server, checkout an orphan branch, and then just git add -all and push to the repo? Will adding the origin from the existing mess with the files on the dev server in any way?

I am very comfortable with Git, but have never come across this problem, and my Google-foo has failed me.

Your help/scorn would be appreciated.

Francois
  • 120
  • 8
  • `git branch` does not have `--orphan`; did you mean `git checkout --orphan`? In any case, `--orphan` is only partly about branch *names* (to the extent that it has to be), and mainly about the way that Git adds the next *new* commit. If you plan to "fuse" two separate repositories, `--orphan` is quite useless. When you `git fetch` commits from some existing repository, you get those commits as they are. Commits *are* history (they don't *have* history, they *are* the history), and you're not making *new* commits now, but rather just retrieving existing history from another Git. – torek Dec 06 '16 at 17:29

2 Answers2

2

Yes, you can use git checkout --orphan dev to realize it, and then use git add . and git push.

But also, there is another way, for your information (create a dev repo for dev code—dev branch, and then push it to production repo):

  1. Create a git repo for dev code (develop branch)
  2. Bash in production repo, add dev repo for remote, use git remote add -f origin2 <URL for dev repo>
  3. git checkout origin2/dev
  4. git checkout –b dev
  5. git push origin dev
Marina Liu
  • 36,876
  • 5
  • 61
  • 74
  • I feel like such a dumb dumb for not thinking about that. Thank you @marina-msft – Francois Dec 07 '16 at 09:23
  • +1 for the other way you suggested, it is a much cleaner way of merging folders into a new branch of an existing repo. – Tyler Jan 04 '17 at 14:40
0

So from what I understand, you have one branch having the production code(master branch). Now, you want to add the dev code in the same repository. If you go with --orphan then the first commit will have a totally new history and will not be related to any of your commits on the master branch. You can still go ahead with this but it may get confusing.

I would recommend just create a new branch in your repo and add the dev code to that branch. It will still be present in your repository but also separated from the master branch. This should keep things organized.

ValyriA
  • 157
  • 2
  • 9