It is definitely time for me to learn about source control, and git in particular.
I do a lot of web development and most of the time I do a lot of development work on the live production server. I know this is really bad.
I just haven’t quite got my head around how local development and then deploying to a live site with git works.
Is the following how it might work out:
-
Set up an environment on my local machine that is as close to my web server as possible
-
Create a git folder where I will develop my project (or download the existing project from the live server).
-
When I’m ready to push my changes commit them in git.
What I’m not sure about is the following:
- How to push my changes out to the live server?
- What if I accidentally delete my local copy?
- What about my database? If I add new tables and data on my local machine will I need to manually make these changes on my live server too?
EDIT
Yes, sorry, not enough detail.
I do all my coding in Coda for Mac, I have a few different projects on the go, but most of these are PHP/YII running on Apache. Database of choice is MySQL.
PHP is going out raw.
If your web site doesn’t require compilation, you might just choose to deploy it directly from the Git repository.
remove them after “git clone”
Your database is another issue. You will probably:
You do all this in bits and pieces on your development machine as though you were doing it in production. When it’s time-to-go, you still really probably want test:
Then, you’ll probably continue working and checking into Git as usual. Often, you’ll be in the middle of implementing an ugly bit of code and need a quick patch to your live site. But you don’t want to just go hack code into your live site. Instead:
A quick note about branching. You can always go back and get ANY version you checked in by date/time, but it’s easier to find them by name. Additionally, once you branch, you can do work on that branch, and then check it in again. Now you have a bifurcation in your codelines. You are making changes to yesterday’s hotness, and it isn’t automatically getting applied to today’s hotness. If you WANT that, you have to manually merge it. Merging is the process of saying “Git client, please try to automatically apply all the code edits from the Release23a/Release23b delta to my latest hotness”.
As you can see, you have some very cool tools available with Git. Deleting your local code isn’t an issue, assuming you’ve been good and checking in frequently.
Note that Git has the concept of local commits. Those don’t save your work from a hard-drive crash until you sync.