“Git is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.” –http://git-scm.com/
In this guide I will walk you through setting up a Git server and accessing it from a Git client over SSH.
Git Server
I am using CentOS 5.3 as my server.
Hostname: gitserver.example.com
SSH Port: 22444 (As opposed to the default port 22, for increased security)
Install Git
yum install git
Create a folder where you will keep the repositories
mkdir /opt/git
Create a git user and change the owership and permissions of the previously created folder to the new user
useradd -c “Git Repository” git
chown git:git git:git /opt/git/
chmod 770 /opt/git
Create an empty project, I am calling my project ‘myproject’
mkdir /opt/git/myproject.git
Initialize the repository using –bare to only include objects at the server side
cd /opt/git/myproject.git
git –bare init
You are done with the Git server, let’s take a look at the client
Git Client
Install Git on your client.
Debian/Ubuntu:
sudo apt-get install git-coreRed Hat/Centos:
yum install git (I am using the rpmforge repo)
Now it’s time to version-control your project.
Create a new folder to put your code (unless it exists already)
mkdir /home/john/myproject
Now it is time to add your project to Git (locally):
cd /home/john/myproject
git initAdd all the files in the current directory to be source controlled:
git add *Commit the changes:
git commit -m “Myproject first commit”
Tell the Git client where to find the server and remote repository
git remote add origin ssh://git@gitserver.example.com:22444/opt/git/myproject.git
Push your project to the server
If you have shared SSH keys:
git push origin masterOR If you dont have configured SSH keys:
git push ssh://git@gitserver.example.com:22444/opt/git/myproject.git master
Now your project is under Git source control
Pull/Clone project:
The below will download the project folder in the current folder:
git clone ssh://git@gitserver.example.com:22444/opt/git/myproject.git
When you make changes to your project, you need to tell Git about it and commit the changes:
cd /home/john/myproject
git add *
git status (Check status)
git commit -a -m “A comment describing the change”
Comments
Leave a comment Trackback