Setting up Magento on Git repository

Setting up Magento on Git repository

Hello everyone! Recently I wrote a short article  Git vs SVN A.K.A. Everyone likes control. Now, I wanted to give you an “real life” example of putting Magento project into Git repository.

So, let’s begin. First of all, I assume that you wish to start with fresh project and that you’ll be doing only back-end programming. This is important because I’ll set up repository only for /app/code/local/ folder. It will keep the repository lightweight and enough for this practical example. At the end, I’ll explain .gitignore file so that you can make modifications to folders you wish to include.

Preparing Git locally

There are two steps you must go through before you start working with Git:

  1. To get started, you need to install Git on your machine – you can find instructions by going on this page.
  2. Next thing you need to do is to find yourself a Git repository that you’ll use for your projects. For this example, I used free private repository located at http://gitfarm.appspot.com/.

Registering (and auto-configuring) of Git repository is extremely simple with gitfarm.appspot.com

Adding Magento files to Git repository

Now, when you have your repository ready, all we need to do is add our files to it. In my example, I’ll add only 1 Magento directory (/app/code/local/) I accomplished that with following commands:

  1. Navigate to your “workspace” directory
  2. Write to console: git clone http://repository_name@gitfarm.appspot.com/git/repository_name.git – we cloned our empty repository to local machine
  3. Navigate to directory named “repository_name” and if you see .git directory inside it, copy your Magento project inside it
  4. Write to console: git add app/code/local/ – this line added our first directory with its files to repository
  5. Write to console: git commit -a -m “Initial repository setup” – with this line executed, we made our first commit with message “Initial repository setup”
  6. Write to console: git push http://repository_name@gitfarm.appspot.com/git/repository_name.git master – and finally we pushed our initial setup folder to repository. When this command is executed, you’ll have your files online in this example.

Now, that wasn’t so hard you should agree. At the moment if you followed these few steps, you have your first Magento Git repository ready for work.

At the moment, anyone with repository location (and password in case of gifarm) can repeat steps 1. , 2. ,5. and 6. and do his/hers share on the project.

Notes:

  • If you haven’t used gitfarm.appspot.com as your repository, steps 2 and 6 might differ (depending of repository setup)
  • if you’ve used any private repository, you will have to authenticate via password or ssh key (depending on setup) – when promited in any of the steps
  • You can add more than one directory to your Git repository by repeating step 4 with different location (all files and folders under that directory will be added)

.gitignore and Magento

.gitignore is Git file that contains a list of files/folders that you wish to keep untracked on repository itself. So, on Magento, as in any other project those are files and folders that depend on your local setup like downloader/, errors/, config.xml,… and so on.

Conclusion

Generally I don’t think that you need whole Magento project on repository, but rather files you edited/added. That’s why I suggest that you put your git project files inside a local copy.

That’s all from me in this one. I hope you learned something new today!

You made it all the way down here so you must have enjoyed this post! You may also like:

How To Connect Google Analytics 4 To Magento 2 Bojan Mareljic
Bojan Mareljic, | 36

How To Connect Google Analytics 4 To Magento 2

How to generate SSH keys for Git authorization Hrvoje Ivancic
, | 21

How to generate SSH keys for Git authorization

How to setup GIT for Magento extension development Branko Ajzele
Branko Ajzele, | 10

How to setup GIT for Magento extension development

11 comments

  1. @Nick Worst. .git .ignore .file .EVER. You forgot local.xml which is the most important file to ignore

  2. I had never heard of this gitfarm 🙂 seems cheap for private repos.

    @anton we use capistrano too, so we push everything to repo except media,var folder.

  3. as discussed one of your earlier blog posts I must disagree with you by not adding the whole magento to git tree.

    Adding the whole Magento to git gives you countless benefits starting from:
    * on version whole installation and gain removing what’s not used and adding whats new on magento version update
    * deployment via git and capistrano
    * diffing against older versions and so on
    * diffing your core overwrites ore extended classes against new versions is also quite handy
    * seamless installation of same site to unlimited locations by just typing git clone

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.