Git how to

20 Apr 2016 / Oscar F
git commands knowledge

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

Configure git

git config --global 'oscfr'
git config --global ''
git init
git add .
git commit -m 'message'

Add a remote repository

git remote add github

Push to the remote repository

When you have made your changes and made a commit locally then you can push the changes to the remote repository with the following command.

git push github main

Setup on a production server

Clone from a main git repository

git clone -o github

and Pull for updates.

git pull github main

Backup your git repo

I think this is the best way.

git clone --mirror

To refresh the backup

git remote update

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
git remote add production ssh://
git push production main

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