Git: Difference between revisions
No edit summary |
(→Links) |
||
Line 118: | Line 118: | ||
== Links == | == Links == | ||
* https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps | * https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps | ||
* https://gist.github.com/noelboss/3fe13927025b89757f8fb12e9066f2fa | |||
[[Category:Linux/Services]] | [[Category:Linux/Services]] |
Revision as of 23:45, 9 February 2018
Usage
- Create repository (on server)
git init
- show changed files
git diff --cached --name-only git diff --name-status
- add files
git add *
- commit changes
git commit -m "Commit-Nachricht" git commit -a # includes add
- send changes to server
git push
- get repository from server
git clone remoteurl
- get latest changes from server
git pull
Configuration
- post-receive hook (execute script on main git server, after receiving push): hooks/post-receive
#!/bin/bash # unset GIT_INDEX_FILE # not needed for post-receive? git --work-tree=/srv/targetfolder --git-dir=/home/demo/proj/.git checkout -f
- or
#!/bin/bash while read oldrev newrev ref do if [[ $ref =~ .*/master$ ]]; then echo "Master ref received. Deploying master branch to production..." git --work-tree=/var/www/html --git-dir=/home/demo/proj checkout -f else echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server." fi done
- make executable
chmod +x post-receive
Special features
- auto-commit when file changes
inotifywait -q -m -e CLOSE_WRITE --format="git commit -a -m 'autocommit on change' %w" file.txt | sh
- or
while true; do inotifywait -qq -e CLOSE_WRITE ~/.calendar/calendar cd ~/.calendar; git commit -a -m 'autocommit on change' done # inotify "-r" for recursive
- or
etckeeper