Using Git for existing environments

I have a question regarding using Git for a website. We already have access to create git private repositories but I don't think we can use that because we already have 3-4 development environments setup on our servers without Git and each environment already has code which is different from each other.

There are three environments
1) Live
2) UAT
3) Test (has the latest code)

We write and test the code locally and manually move each point from one environment to other using merging software and test at each environment.

Now we want to use git because manually moving code is a lengthy process. Git doesn't seem to have physical files.

So we have two concerns:

1. There is different code already existing on three environments.
2. Testing the code on each environment using the web server.

What is the best way to go about it?

Thanks,
Sukhwinder SinghAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

evilrixSenior Software Engineer (Avast)Commented:
>> Git doesn't seem to have physical files.
It does, but this is all hidden internally. It's not like (for example) SVN where each branch is a separate copy of all the files on disk. Git keeps a diff of each branch and when you switch branches it just updates the diff.

Am I right in thinking that the workflow of you code is such that it starts off in "Test", is then merged to "UAT" and then, finally to "Live"? If so, this is what I would do to set up a Git repo.

1. First of all create an empty repo
2. Copy "Test" into master
3. Create a new branch from master called "test" (or something similar)
4. Because test is create from master it will contain everything from master
5. Switch back to master
6. Delete all the files from "Test"
7. Copy "UAT" into master
8. Create a new branch from master called "uat" (or something similar)
9. Switch back to master
10. Delete all the files from "Test"
11. Copy "live" into master
12. Create a new branch from master called "live" (or something similar)

When you are done your repo should look something like this...

* (HEAD, master, live)
|
* (uat)
|
* (test)

In other words, "live" will be a branch of "uat" and "uat" will be a branch of "test". You can then merge changes from "test" into "uat" and changes from "uat" into "live".

Note, this only works if my assumption of each environment being related in a grand-father, father, son way is true. If it's not then you'll struggle to use Git to do this.

Is that the sort of thing you are trying to do?
0
Sukhwinder SinghAuthor Commented:
Thank you for the answer.

>> Am I right in thinking that the workflow of you code is such that it starts off in "Test", is then merged to "UAT" and then, finally to "Live"?

Yes that is right.

I have couple of more questions:

1) Are you talking about using the private github repository online or there is some git server which we can locally install? If it has to be locally installed, on which server it should be installed (live?) and are there any available git server options?
2) When you say create a branch,  so after creating a branch we need to checkout the code to each environment to a directory, which will be a web server document root and it'll have all the physically files which we can test?
0
evilrixSenior Software Engineer (Avast)Commented:
1. Git doesn't need a "server" as such because, unlike SVN, each person has a completely local copy of the repo. You can set up your own Git "truth" repo server that everyone can sync to. If you want to "push" to the production servers then each server will need a git repo, that you push to. Using git to deploy; however, is not ideal and I would stick to using something like rsync.

2. You will be creating the branches on your local repo. You will need to push these branches to whatever server(s) you want to have copies. On the "live" server you will have the "live" branch checked out. On the test server you will have the "test" branch checked out and on the "udt" server you will have the "udt" branch checked out. Pushing to the server won't be enough to deloy. You'll then have to execute a git pull on each of the servers to update the working directory from the branch that you've push to. Again, I would advise against using Git as a way of deploying. It's possible but it's really messy and not an idea solution. Prefer something like rsync to deploy.
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sukhwinder SinghAuthor Commented:
Thank you very much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Git

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.