git_update/readme

62 lines
3.8 KiB
Plaintext
Raw Normal View History

# Overview
git_update.sh is a bash script performing a punctual synchronization of a git repository. It can either be a new clone or an update.
CAREFUL: git_update.sh is not working-directory safe and can delete your work.
# Download
Download the git_update.sh file.
Bash and Git have to be installed on your computer.
# Use
## Help extract
2024-07-23 19:34:37 +00:00
NAME
git_update.sh
SYNOPSIS
git_update.sh [-h] [-r ref] [-d dest] [-H] [-a] repository
2024-07-23 19:34:37 +00:00
OPTIONS
-h prints the help.
-r specifies the reference to the commit to be synchronized. It can be a tag or a branch. By default, it is the last commit of branch main.
-d specifies the destination of the clone or update. Directory must be empty if a new clone is to be made.
2024-07-23 19:34:37 +00:00
If the repository to be cloned is local, and its path is passed as a relative path, the path should start from the destination.
To avoid mistakes, absolute paths are advised.
-H allows the $HOME directory to be used by git_update.sh. By default, git_update.sh cannot access $HOME to prevent default behavior.
If you need the global .gitconfig located in your $HOME to be used, you should supply the -H option.
-a specifies that the aggressive option of the git garbage collection must be used. Only advised when changes happen in many different objects. Will slow down the execution.
DESCRIPTION
This script will replace the destination with the wanted commit of a git repository. The history is not preserved but tags are. Untracked files remain.
The git commands have been chosen so as to minimize the memory and bandwidth usages.
## Cloning
git_update.sh will only clone in an empty repository, by default the current working directory.
If called in a repository with a .git directory, it will update (see below). If called in a repository with untracked files, it will fail. Only the commit and the necessary objects will be cloned. The commit can be indicated through a reference, either a tag or branch, otherwise the last commit of branch is the default.
git_update.sh clones using
" git clone --recurse-submodules --shallow-submodules --depth=1"
## Updating
git_update.sh will update if the repository already contains a .git. Untracked files and directories will be kept. Any local modification to a tracked file or created tracked file will be deleted in favor of the new commit. The history will only contain the very last commit.
git_update.sh updates using
" git fetch --tags --depth=1 --prune --prune-tags --force origin $ref
git reset --hard --recurse-submodules FETCH_HEAD
git submodule update --init --recursive --force --depth=1 --remote
git reflog expire --expire=now --all
git gc --prune=now [--aggressive]"
## Examples
A) Cloning the last commit of a branch into a non-existing directory
2024-07-23 19:34:37 +00:00
./path/to/git_update.sh -r myBranch -d myDirectory https://git.mydomain/myname/myrepository.git
Result: a directory myDirectory has been created in the current working directory. It is filled with the files of the last commit of branch myBranch as well as the .git. The history only shows the last commit.
2024-07-23 19:34:37 +00:00
B)
2024-07-23 19:34:37 +00:00
# Development process
git_update.sh has been written by the French association Jean-Cloud (https://www.jean-cloud.net), in the process of developing Shlagernetes, a new orchestration tool. Shlagernetes allows storing services on fallible second-hand servers and tries to consume the less possible resources.
Several tests have been performed in order to find the most energy-saving Git commands.
You can find them under /test/performance_tests.
Please refer to /doc/development_explanations for more information about the tests and choices made in the elaboration of git_update.sh.
# Testing
# How to contribute
If you have any suggestion or question about git_update.sh, please contact us at contact@jean-cloud.org. We would be delighted to hear your feedback.