>How to Set up Git on Magento Site

How to Set up Git on Magento Site

In fact, there are several channels that allow Git setup such as Bitbucket, GitHub, GitLab. In the scope of this article only, we will show you the way to set up Git for Magento site via https://bitbucket.org.

Firstly, go to https://bitbucket.org. You need to sign up for a new account or log in if you already had one. Then, you can find Repositories tab on the top left of the menu bar, just click on it and choose the action “Create repository”.

Now is the time to log in SSH and use code. In the followings, we mention two different ways to use Git via HTTPS link or SSH.

Git setup via HTTPS

Use cd folder_contains_code to open the folder that contains code and Git init to create an init for Git.

Git remote add origin link: from Bitbucket, in the Actions column on the right, choose “Clone” and then copy the link written after “git clone”.

vi .gitignore: create (if file .gitignore hasn’t existed) or modify that file to remove unnecessary folders such as var/, app/etc/local.xml, media/catalog/product/cache. Besides, you also can add other folders of Magento system like app/etc/modules/. However, it’s not recommended adding these files because there are many modules that are directly added here.

app/code/core/
app/design/adminhtml/default/default/
app/design/frontend/base/
app/design/frontend/default/default/
app/design/frontend/default/blank
app/design/frontend/default/iphone/
app/design/frontend/default/modern/
app/design/install
app/etc/modules/Mage_All.xml
app/etc/modules/Mage_Api.xml
app/etc/modules/Mage_Bundle.xml
app/etc/modules/Mage_Centinel.xml
app/etc/modules/Mage_Compiler.xml
app/etc/modules/Mage_Downloadable.xml
app/etc/modules/Mage_Weee.xml
app/etc/modules/Mage_Widget.xml
app/etc/modules/Phoenix_Moneybookers.xml
app/etc/config.xml
app/etc/local.xml.additional
app/etc/local.xml.template
app/locale/en_US/
app/Mage.php
cron.php
cron.sh
downloader/
errors/
favicon.ico
includes/
index.php
index.php,sample
install.php
js/blank.html
js/extjs/
js/lib/
js/prototype/

js/varien/
js/calendar/
js/flash/
js/index.php
js/mage/
js/scriptaculous/
js/tiny_mce/
lib/3Dsecure/
lib/flex/
lib/googlecheckout/
lib/LinLibertineFont/
lib/PEAR/
lib/Varien/
lib/Zend/
LICENSE_AFL.txt
LICENSE.html
LICENSE.txt
media/downloadable/
media/import/
nbproject/
pear/
php.ini.sample
pkginfo/
shell/abstract.php
shell/compiler.php
shell/indexer.php
shell/log.php
skin/adminhtml/default/default/
skin/frontend/base/
skin/frontend/default/blank/
skin/frontend/default/blue/
skin/frontend/default/default/
skin/frontend/default/french/
skin/frontend/default/german/
skin/frontend/default/iphone/
skin/frontend/default/modern/
skin/install/
var/
pear

Git add: to commit the first time (otherwise, you just need to add the files that have already been changed, also Git status can be used to see the changes). To use Git for the first time, system will require configuring some information. Some usual configuration are:

  • Git config core.fileMode false: skip changes about chmod
  • Git config –global user.email “example@mail.com”: email used to log in bitbucket
  • Git config –global user.name “username”

After cofig (if necesssary), we continue to commit.

Git commit -m “first commit”: create commit to push on bitbucket with commit name written in the mark.

Git push origin master: push commit onto bitbucket. 

Git setup via SSH

This method adds several extra steps but gives better security (in comparison with Git via https) in return. Firstly, you go to /Users/Admin/.ssh then use ls -a .ssh to check wether any ssh key has existed. Ssh key usually has this form:

id_rsa.pub
id_dsa.pub
id_ecdsa.pub
id_ed25519.pub

If you haven’t had ssh key, it’s essential to create a new one: ssh-keygen -t rsa -b 4096 -C “example@mail.com. After that, system will ask you where to save it, just hit “Enter”. Then keep continue to fill up the password for that key:

Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]

So, we have done creating ssh key (usually named là id_rsa or id_rsa.pub). The next step is to add key into ssh-agent:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

Then add ssh public key (id_rsa.pub) into bitbucket account: cat ~/.ssh/id_rsa.pub | clip (This is used to copy content of id_rsa.pub). Now you have to go to bitbucket account and paste the copy in the section “add ssh key” in Bitbucket setting.

Check whether the key is added or not by ssh -T git@bitbucket.org. If you see a notification as “Logged in as …”, that means you add key successfully and be ready to keeping using Git.

cd folder_contains_code: go to the folder that contains code.

Git nit: create an init for Git.

Git remote add origin link: you can get the link from Bitbucket, choose Clone action and copy it from “git@bitbucket.org” until the end of the link.

From here, we keep doing it similarly as with link https:

create .gitignore

Git add

Git config (if needed)

Git commit

Git push

If you get into any issue when following this instruction or even just want to discuss in more details, please feel free to leave a comment. Sharing ideas is a good way to get us all improved.

< Previous Post
Next Post >