Git for the lone programmer

Question:

I work with a small project, at my disposal:

  1. The workstation I'm writing the code on
  2. Test server, where I automatically upload the code and see the result, and also run the tests
  3. The combat server to which I upload the changes after testing

I want to work through Git so that I can quickly create branches and switch between them.

I want to work something like this:

  1. Received a bug report or a request to add functionality
  2. I created a branch for this fix and switched to it
  3. I wrote the code, periodically uploading it to the test server to see what happened
  4. The code is written, the tests are passed, I commit and merge the finished code into the master branch
  5. From there (preferably automatically) the code takes the production server.

I read a lot of materials and did not understand how to achieve the workflow I needed. First of all, it's not clear to me where the repository should be located and how to work with it through Phpstorm.

Answer:

If I understand correctly, then you are not familiar with git yet. Git differs from previous generation systems in its decentralization, i.e. each repository acts on its own, so all work, in theory, can be done on one machine without raising any servers. After executing the git init command (in PHPStorm it is done through the menu), the repository itself will be created in the root of the project as a .git folder. It will still be useful to us.
As for the "central server", I recommend creating an account on bitbucket – this is a service for storing and managing git repositories that allows you to start any number of private repositories. We also need it.

The workflow that you described, with the exception of deployment and tests, is practically a copy of the description of git-flow . git-flow assumes the existence of a master branch, which contains the production code, and a dev branch, which contains the current version. To create new features, feature/some-name branches are created, which are merged into dev at the end; when bugs are hotfix/some-name branches are created, which are merged in both dev and master . The whole thing, of course, is already automated by the gitflow package, for which there is a plugin in PHPStorm, thanks to which all these actions will be even easier.

There are two (three) ways with deployment. Firstly, the git supports so-called hooks , which will allow you to run scripts on various actions with the repository, which will allow you to attach handwritten scripts to some actions. But this is not very correct, since this very script will be launched for each commit. If you have created an account on Bitbucket, there is an alternative way – hooks in the Bitbucket system itself, which are executed every time new commits are uploaded and allow you to make an HTTP request at a specific URL. Here you can attach staging and production servers, forcing them to update on a similar request. In this case, you will have to write out the deploy key to these servers in bitbucket (the most common ssh keys), which will be needed in order for these servers to pull the fresh code.

However, in an amicable way, you need Jenkins , who will handle this whole thing, otherwise, of course, you will constantly have to do something manually. Jenkins is an always-on integration server that is specifically designed to automate these kinds of processes. In this case, a hook from bitbucket will be sent to Jenkins, which will itself filter the updated branches and, based on them, launch internal projects. In this case, you will need to configure Jenkins' ssh connection to the servers and create two projects – deploy and run tests on the staging server and deploy on the production server; the first one should be launched by hooks and roll out the freshest loaded branch, and the second one should be launched only by the button, or by updating the master branch.

If you still do not know some things, but I thought the opposite, write, I will complete the answer.

Scroll to Top