- Magento Extensions Development
- Jérémie Bouchet
- 803字
- 2021-07-14 11:02:01
Managing our work with Git source control
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.
Bitbucket registration
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.
Tip
Check This is a private repository if you want to hide your repository from the general public, so that only selected people can see it.
- 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
Committing our work
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/ [...]
Note
The source code can be found in the
by-chapter
branch of the Git repository, in theChapter1
folder. - 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/
Note
Note the
-f
option, to force Git to add the file even if it is stored in an ignored folder. If you don't use this option, Git will inform you that it can't add the file. - Commit your additions:
git commit -m "Adding the first extension files"
- Link your repository to the Bitbucket repository:
git remote add originhttps://YOUR_USERNAME@bitbucket.org/blackbirdagency/ticket-blaster.git
Tip
This line is to modify your repository configuration.
- 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.
Discovering other Git servers!
There are others Git storage services online, such as and different public/private repo policies.
You can create your own private Git server too, which can be dedicated to your company or organization.
- Vue.js 3.x快速入門
- Google Flutter Mobile Development Quick Start Guide
- Vue.js 3.x從入門到精通(視頻教學版)
- Reactive Programming with Swift
- Elastic Stack應用寶典
- Visual C
- Windows Forensics Cookbook
- AutoCAD VBA參數化繪圖程序開發與實戰編碼
- Mastering JavaScript Design Patterns(Second Edition)
- Active Directory with PowerShell
- Statistical Application Development with R and Python(Second Edition)
- Extreme C
- 單片機原理及應用技術
- Oracle Data Guard 11gR2 Administration Beginner's Guide
- 官方 Scratch 3.0 編程趣味卡:讓孩子們愛上編程(全彩)