What is GIT?
Git is one of the most popular free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Working on code requires a version control system and Git is highly recommended for versioning PHP code, whether you work on code alone or in a team. It provides patches, history, rollbacks, code versioning and more for your PHP project as well.
Git is available for download for multiple operating systems.
To install Git on Linux operating systems best is to use your package manager,
For example, Debian based distributions using
sudo apt-get install git-all
Or for Fedora based distributions:
sudo yum install git-all
macOS Sierra and OS X (until El Captain) don’t include an up to date Git. Git is bundled with macOS, here is how to upgrade it:
If you do not have brew, install it:
- Install Xcode from the App Store and run
xcode-select --installafter the successful installation.
- Install brew
Now install Git, brew will delegate a soft link into a higher path’ed directory:
brew install git
You could install Git in other ways (there is an official .dmg-image with an installer). But this will force you to always handle those updates by yourself. This will update everything:
brew update && brew upgrade `brew outdated`
Beside the Windows installation on the main download page there is also Git for Windows, providing dedicated instructions for installation and adds neat shell integration.
Commit message is the log information about the change made to the code in the repository. Generally these must be informative and include all the information needed about the change. For small changes they can be short, for bigger changes they should be longer.
Some useful rules of a thumb for commit messages:
- Make the title of the commit message 50 characters or less;
- Put more information in the body part of the message (body starts after two new lines after the title);
- Use imperative for the message title -
Add new functionnot
New function added;
- Wrap body text to 72 characters
A Note About Git Commit Messages, by Tim Pope suggests a model you should use for writing useful Git commit messages:
Capitalized, short (50 chars or less) summary More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together. Write your commit message in the imperative: "Fix bug" and not "Fixed bug" or "Fixes bug." This convention matches up with commit messages generated by commands like git merge and git revert. Further paragraphs come after blank lines. - Bullet points are okay, too - Typically a hyphen or asterisk is used for the bullet, followed by a single space, with blank lines in between, but conventions vary here - Use a hanging indent
When creating Git repository in public Git hosting services such as GitHub, best practice is to add also some of the additional files to the repository which describe the repository and your code with more details:
README.md- introduction file about the project; (art-of-readme).
CHANGELOG.md- Change log of the tagged versions using semantic versions. Dedicated site Keep a CHANGELOG describes, why is useful having a separate change log for your repository and how to format it.
CONTRIBUTING.md- Open source projects usually add the file describing how to get involved and send your patches to the repository.
LICENSE- License of the repository.
CONDUCT.md- Some open source projects include also their code of conduct to let the users know what is appropriate and what not. Specially in larger and diverse communities having such information adds extra value to the project. Having a welcoming and inclusive environment is important for people contributing to your project.
Useful resources to read more about Git:
- Git homepage - homepage of Git version control system with documentation;
- Pro Git book - detailed and useful book dedicated to Git usage with usage examples;
- Interactive Git Tutorial from GitHub
- Git Lint - PHP library for linting git commit message style
- Nomad PHP: Commit Messages I have seen - lightning talk
Content of this work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license. Code snippets in examples are published under the CC0 1.0 Universal (CC0 1.0). Thanks to all the contributors.