How can I use Git repositories for web development (and deployment)?
Coming from a simple "edit directly on ftp" workflow, I want to try source version controlling. As I can imagine, GIT is a very popular choice.
I'm a single developer. I have multiple websites I work on (each one in /home/domains/) on the remote server (Linux) and I wish to start working on them locally (Mac OS) and then pushing them back (updating the remote files).
I didn't however understand how git is supposed to work for me. It looks like I have to have a "bare" repository, which I can't have bec开发者_运维技巧ause my projects already have files and folders, so that means I'd have to create a new bare repository and then push stuff locally and afterwards pull remotely.
This seems a bit weird, having 3 repositories (1 local and 2 remotes) when I only would work on 2 folders.
Can I get some advice?
There are two standard, sane, options if you have online access between your server and your local system.
First, you can add a remote for the other repository and pull all committed changes from the other repository before you start making changes. This means, for example, if you make a change on the local system, you will have to ssh over to the server and pull to get the changes over there.
Second, you can create a bare repository to act as the master. This is the standard model for shared repositories, especially when there are multiple users involved but it works when one user is involved and is preferred when there might not be full-time bidirectional access between the two systems. This bare repository could be on the mac system, on the linux server, or on a third system (such as github, for example). The workflow in this case would be to pull all changes from the bare repository, make a change, commit, and then push that change to the bare repository. Absent special hooks, you still would need to ssh over to the server and issue a pull to update the live website.
You could create the new repository by doing a git clone --mirror --bare
from the server repository. Afterwards you would git add remote origin URL-TO-NEW-BARE-REPOSITORY
on the server. You could either do the same on the macosx system or git clone URL-TO-NEW-BARE-REPOSITORY
It is technically possibly to configure the system to allow the macosx system to push to the checked out linux working directory. I do not recommend this, especially if you might be making changes on that repository as well, since the process might/would destroy any uncommitted change. A similar problem could happen with automatic hooks which would automatically send/checkout incoming commits to the live webserver directory.
For reference purposes, consider http://toroid.org/ams/git-website-howto and http://joemaller.com/990/a-web-focused-git-workflow/
My workflow is like this:
- I have a remote repo and a local one (they are normal repos, not bare ones)
- I work on my local repo
- I commit
- I push my changes to remote repo
- I ssh to the remote machine and run
git reset --hard
on remote repo to update the files
Works pretty well for me, especially because I use Fabric to do the push and reset steps, so it comes down to single fab push
.
To clarify I'm a single developer, might not work so well if you develop your webpage in a larger team.
精彩评论