0

To learn the basics of Git, I set up a git repository for my wordpress page, where I try to code some small plugins etc. in PHP. I only have FTP acces to my webhost, so I use a tool called "git-ftp" to transfer my committed changes to my webserver. So far it works, but since I am used to test every small change in my code, I have to commit my changes all the time, and after an hour of coding I have 234 commited versions, which can't be the way git is meant to work.

How can I improve my setup? I actually don't want to "mirror" my wordpress installation on my local machine to test my modifications, but I can't see a way around this.

I'm new to Git, so maybe someone can tell me efficient ways to use git for webpage coding?

mischa.mole
  • 357
  • 2
  • 12

2 Answers2

1

I would suggest a different setup; stop using git-ftp for development; ftp your working directory manually instead, or setup your editor to save to ftp directly.

When you are satisfied with what you have build; you commit it and possibly use git-ftp to push this to production.

Using this setup for development is way too redundant and not what git is meant to be used for

Sjon
  • 4,989
  • 6
  • 28
  • 46
  • But for that, it would be necessary to be able to test my code locally. Without Git, I was modifying changing my code and testing it in the "real" environment, since I was always too lazy to setup PHP/mysql etc. on my machine. My Blog has probably just a few visitors per day, so it didn't really matter if I "ruined" something. But probably I have to change my workflow altogether..... – mischa.mole Nov 04 '15 at 10:22
  • Even for a small site it doesn't hurt to do things *the right way*. Your current method is only suited for production, not development usage. That's why it doesn't feel efficient – Sjon Nov 04 '15 at 10:24
  • Thank you! Unfortunately I can accept only one answer, but I guess I know how to proceed now! – mischa.mole Nov 04 '15 at 10:31
  • You're welcome, you can upvote my answer if you agree with it, regardless of accepting another – Sjon Nov 04 '15 at 10:32
1

A common way in developing web applications is always to "mirror" at least the source of the production environment to the development environment.

So you can easily test your new code.

Git brings a feature named branches to you so you could setup different branches.

A good way is to setup different branches like:

-- master (should always be there)
-- production (local branch on your production server)
-- develop (maybe not needed for smaller projects)
-- feature branches for every feature you want to make

I you are developing something new, you can setup a remote branch called newfeature and commit your changes to that branch, check out this branch on your production server, yes I'm sorry there is no other way than committing a lot, if you want to test in on your production server.

The advantage is, when your feature is working, you can merge it to your master and later on to your local production branch on the server delete the newfeature branch.

The production branch is just to feel a bit safer, If something would go wrong on your production server you can just check back to the working production branch.

A good way would be to get a server with ssh and git, I would recommend the git-ftp solution to nobody who really develops a web application.

Maybe you can find a bit inspiration in this answers: Git Push into Production (FTP)

Community
  • 1
  • 1
swidmann
  • 2,787
  • 1
  • 18
  • 32
  • Sounds good to me....unfortunately, FTP is the only possibility to access my host, it's not my power to change that! But it looks like there is no way around having everything stored locally too. – mischa.mole Nov 04 '15 at 10:25
  • Well, sometimes you have to take the hard way ;) – swidmann Nov 04 '15 at 10:29