A brief explanation about how to install and setup a git repository will be described here.
In order to access your git repositories remotely you must setup a SSH account with bluehost, so log in
into your Bluehost account and look for the option SSH. You must sent an copy of your ID and wait for them to setup the account for you
(I used my webcam to take a picture of my ID and that was more than enough).
Installing git in your Bluehost server.
1) Create a place to install the git binary files.
In my case, I’ve created a local folder “.local” inside my $HOME folder (~/.local).
#cd ~ #mkdir .local
2) Edit your .bashrc file and add the following line. Logout and login again to apply changes.
export PATH=$HOME/.local/bin:$HOME/.local/usr/bin:$PATH
3) Create a folder “~/.local/src”, download the latest version of git (in my case 1.7.4.3) and compile it
#cd ~/.local #mkdir -v src #cd src #wget http://kernel.org/pub/software/scm/git/git-1.7.4.3.tar.gz #tar -xzf git-1.7.4.3.tar.gz #cd git-1.7.4.3 #./configure --prefix=$HOME/.local LDFLAGS="-L/lib64" #make #make install
How to setup and access a git repository in the server locally
1) Create a “~/git/repository” folder that will contain your files
#cd ~ #mkdir git #cd git #mkdir repository
2) Create a bare repository using git init
A bare repository works like a SVN server repository. This means that a bare repository only keeps track of
changes from someplace else and you actually don’t work inside it.
#cd ~/git/repository #git init --bare --share
3) Create a working copy folder by cloning your empty repository, add files to the cloned folder, commit and push the changes back to your bare repository.
In order to use the bare repository, a master banch needs to be created. This is accomplished by using “git add .”.
This command tells git to add all files and folders to the repository (in this case I’m creating a test file,
here you could copy your files to this folder before executing this command).
#cd ~/git #git clone ~/git/repository myfolder #cd myfolder #echo This is a test file > text.txt #git add .
Note that, distinct from SVN, you must commit then push the changes back to the bare repository. In git, the command commit
saves the changes to your cloned local repository; the command push will actually send the changes to your main bare repository.
#git commit
#git push ~/git/repository/ master
At this point you have a fully functional bare repository.
To test it, lets delete "~/git/myfolder" and create another clone.
#cd ~/git/ #rm -rf myfolder #git clone ~/git/repository/ myfolder2 #cd myfolder2 #cat test.txt
You should be able to see the contents of test.txt
Accessing your bare repository remotely
Please note that I'm not covering how to install git in your local machine, but that should not be an issue since
the process above cover any linux install. For windows users, there are plenty of how-tos in the web. The binaries
can also be found in http://git-scm.com
The steps below describe how to access a remote git repository through SSH installed in BlueHost
1) In your local machine, create a folder and use "git init" to start a fresh repository.
This folder will contain a working copy of your repository.
mkdir mylocalfolder cd mylocalfolder git init
2) Create an alias "myrepository" to identify the remote repository to git. Note that myusername@mydomain.com
must be changed by your actual domain hosted on Bluehost. Please also check the path to your home folder
(you can use "echo $HOME" in the server to check it)
git remote add myrepository myusername@mydomain.com:/home/myuser/git/repository/
3) Map the git commands "git-upload-pack" and "git-receive-pack".
This is the trick that makes git work remotely with Bluehost. Remember checking and replacing "/home/myuser" folder
for your actual home folder (you can use "echo $HOME" in the server to check it)
git config add remote.myrepository.uploadpack /home/myuser/.local/bin/git-upload-pack git config add remote.myrepository.receivepack /home/myuser/.local/bin/git-receive-pack
Alternatively, you also can change thoose properties by editing the file "mylocalfolder/.git/config"
The file should contain a session like this
[remote "myrepository"] url = myusername@mydomain.com:/home/myuser/git/repository/ fetch = +refs/heads/*:refs/remotes/repository/* receivepack = /home/myuser/.local/bin/git-receive-pack uploadpack = /home/myuser/.local/bin/git-upload-pack
4) Finally, pull your files from your bare repository (branch master in this case) to your work folder
git pull myrepository master
Your working copy is ready to go. Just remember, after any change use
git add . git commit git push myrepository master
A good GIT by example guide can be found at
http://sysmonblog.co.uk/misc/git_by_example/
Please let me know of any typos.
I hope you all find this tutorial useful!
Fernando
References
http://codepie.org/install-git-on-bluehost-shared-hosting.html

























