Git how to

20 Apr 2016 / OscFr

This post is basically just some notes to myself about the basics of how to use Git.

Create a new Git repository from an existing code base

git init
git add .
git commit -m 'message'

Add a remote repository

git remote add origin
git push origin master

Setup on a production server

Clone from a main git repository

git clone

and Pull for updates.

git pull origin master

Alternative setup on the production server

An alternative way to setup and handle the production server is to use a githook.

mkdir -p /var/www/project_name
chown -R git:git /var/www/project_name
mkdir -p /home/git/project_name.git
cd /home/git/project_name.git
git init --bare
sudo nano /home/git/project_name.git/hooks/post-receive and add the following:
 GIT_WORK_TREE=/var/www/project_name git checkout -f
chmod +x hooks/post-receive
chown -R git:git /home/git/project_name.git
git remote add production ssh://
git push production master

For more


Git Reference


[1]: Git Reference Retrieved: 3 Juli 2018 20:00 Git Reference
[2]: Using git to deploy code to a server Retrieved: 20 April 2016 21:00 Using git to deploy code to a server