Once the project has begun, it may be a good thing to take care of code revision and eventually collaboration with other developers.
Git is a distributed revision control system developed by Linus Torvalds in 2005, initially for Linux kernel development. It has begun to replace the Subversion (SVN) system in a lot of companies, thanks to its full-fledged repository and independence from network access and a distant server.
As soon as you start to work with other people and developers, the repository must be always available on the Internet. You have two choices to do this: the first is to create a Git repository on your own server (a private server in your organization, or a rented dedicated server), and the second is to use a service that provides a repository for you. In this recipe, we will register our code on Bitbucket.
Note
GitHub and Sourceforge provide the same services, but Bitbucket offers more free services and is fully integrated with other Atlassian services such as Hipchat or Jira. It is up to you to make your choice according to your needs and environments.
Perform the following steps for Bitbucket registration:
Sign up to Bitbucket (https://bitbucket.org) by following the instructions on the website:
In the upper-right corner of any page, click on Create, and then click Create repository:
Enter your repository name and choose whether your repository will be public or private.
That's it for Bitbucket. Keep this window open for future instructions.
Go to your terminal and install Git on your computer by running the following command line:
sudo apt-get install git
In the following step, we will commit our code to a new repository, and then we will push the repository to Bitbucket:
Initialize an empty repository by going to your Magento source folder and running the following command:
git init
Check that your repository has been created and is empty:
git status
Create a
.gitignore
file in the root of the repository and add the following content to it:#Git ignore for extensions writing /app/code/Magento/* /dev/tests/ /lib/ [...]
Verify that the
.gitignore
file is taken into account by runninggit status
again:git status
You can see that only
.gitignore
is taken into account by Git.Note
What happened? In fact, in a Magento project, especially with Magento CE, the source files are always available online and are the same for all. That's why you can presume that each of your collaborators first, and every client next, will run Magento. This is your code, it is unique and important, and that's why your code is the only thing to keep in your repository. Note for later: if you need to add another folder in your repository, just remove the corresponding ignore line.
Run the following commands to add and commit the
.gitignore
file:git add .gitignore git commit .gitignore -m "Ignoring all resources files"
Now your repository needs to be filled with the files of our project. Repeat the operation for all the files the extension needs with the command
git
add
<folder
|
filename>
:git -f add app/code/Blackbird/
Commit your additions:
git commit -m "Adding the first extension files"
Link your repository to the Bitbucket repository:
git remote add originhttps://[email protected]/blackbirdagency/ticket-blaster.git
Finally, send the files and commit comments to Bitbucket by pushing the repository:
git push -u origin master
You will find your files by clicking on your repository name on https://bitbucket.org/, proving that the files have been sent and are available for other users.
Note
Take note not to send useless files.
When you are creating an extension, the people who install your code will already have a Magento instance. It is very important to share only the extension files and not Magento and customizable files, which are already modified or installed by your client.
That's why we have chosen to ignore almost all files by default, and to force a git add with the -f option when the file we need to share is placed in an ignored folder.
There are others Git storage services online, such as https://github.com/ or https://sourceforge.net/, which offer different storage spaces and different public/private repo policies.
You can create your own private Git server too, which can be dedicated to your company or organization.