how-to-git

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 https://github.com/oscfr657/Gallery657.git
git push origin master

Setup on a production server

Clone from a main git repository

git clone https://github.com/oscfr657/Gallery657.git

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:
#!/bin/sh
 GIT_WORK_TREE=/var/www/project_name git checkout -f
Ctrl-x
chmod +x hooks/post-receive
chown -R git:git /home/git/project_name.git
git remote add production ssh://website.com/home/git/project_name.git
git push production master

For more

What-is-a-bare-git-repository

Git Reference

References:

[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