Git: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
== | == Create repository (on server) == | ||
<blockquote> | <blockquote> | ||
<pre> | <pre> | ||
Line 9: | Line 7: | ||
</blockquote> | </blockquote> | ||
== Initial checkout of remote repository == | |||
<blockquote> | |||
<pre> | |||
git clone https://gerrit.wikimedia.org/r/p/mediawiki/core.git | |||
git clone ssh://user@server/srv/git/git-repo.git | |||
</pre> | |||
</blockquote> | |||
== Get latest updates from server == | |||
<blockquote> | |||
<pre> | |||
git pull | |||
(git fetch && git merge) | |||
</pre> | |||
</blockquote> | |||
== Change files and commit == | |||
* show changed files | * show changed files | ||
<blockquote> | <blockquote> | ||
Line 37: | Line 52: | ||
<pre> | <pre> | ||
git push | git push | ||
</pre> | </pre> | ||
</blockquote> | </blockquote> |
Revision as of 16:14, 10 November 2018
Create repository (on server)
git init git init --bare
Initial checkout of remote repository
git clone https://gerrit.wikimedia.org/r/p/mediawiki/core.git git clone ssh://user@server/srv/git/git-repo.git
Get latest updates from server
git pull (git fetch && git merge)
Change files and commit
- 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 git commit -am.
- send changes to server
git push
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
- or