Pergunta

I am currently looking into Git to manage the code for a website. I always worked locally and on the production server. I want to start working with Git more and I would like to use the https://www.atlassian.com/git/workflows#!workflow-gitflow

So basically, the master branch should be what I have on the production server? But locally, I got some few features I started working on and that's not pushed on the production server.

Can someone help me to get things going?

Foi útil?

Solução

If you don't have any versioning so far, create a local folder and copy the website files down into it. In that folder run git init, then git add . to add all files, and git commit -m'Add initial files' (or whatever message you want) to commit the first state of the repo.

If you want to work on a 'dev' branch, just do git branch dev in there to create the branch, then git checkout dev to switch to it, or you can do both of those in one shot with git checkout -b dev, which creates the new branch and switches you to it. Now copy over the files from the work-in-progress folder over those, and let it overwrite whatever it wants to. This is your new project folder now. You can replace the old one, once you're sure it worked.

At this point you can use git diff to see what you've updated. When you're ready to commit your changes (which you should do often; I like to commit each logical change, like the addition of a feature, the fixing of an issue, the refactoring of some names, etc), add and commit them. When you want to merge dev into master, just git checkout master to switch over, and git merge dev to merge in dev. Then you can git checkout dev and go back to developing.

Since you're working alone, you'll probably only have a set of changes on top of master in dev, so git will do a fast-forward merge, which is basically just moving the master label up to where dev is, and not actually creating a merge. If you want to create the merge, give the commit call a --no-ff flag (for no fastforward).

Before jumping into git flow, you should read through the Git Pro book, especially Chapter 3 on branching and merging. You'll need to figure out a deployment method - it could just be rsync. It's considered a bad idea to have a copy of the repo on your server checked out to the latest commit on master. Git is not a deployment tool. It's better to copy over from master to the site in whatever way works best for you.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top