Git how to
This post is basically just some notes to myself about the basics of how to use Git.
Configure git
git config --global user.name 'oscfr'
git config --global user.email 'oscfr@oscfr.se'
git init
git add .
git commit -m 'message'
Add a remote repository
git remote add github https://github.com/oscfr657/Gallery657.git
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 https://github.com/oscfr657/Gallery657.git
and Pull for updates.
git pull github main
Backup your git repo
I think this is the best way.
git clone --mirror https://github.com/oscfr657/Gallery657.git
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:
#!/bin/sh
GIT_WORK_TREE=/var/www/project_name git checkout -f
Ctrl-x
git remote add production ssh://website.com/home/git/project_name.git
git push production main
For more
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