It can be different from the actual branch. CAREFUL, the command git branch will always show the original branch name even though a branch switch has happened.
-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 main is the default.
CAREFUL: the command git branch will always show the original branch name and will not follow the eventual branch changes.
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.
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.
git_update.sh has been written by the French association Jean-Cloud (https://www.jean-cloud.net), in the process of developing Shlagernetes, an orchestration tool.
Shlagernetes allows storing services on fallible second-hand servers and tries to consume the less possible resources.