GIT

Useful commands

Shallow cloning

Clone a repository truncating the history to a certain depth. With a depth of 1, we copy only the latest revision of every file in the repo.

git clone --depth 1 repository://url

git clone --depth 1 https://gitlab.com/hkzlab-retrocomputing/AKAB_Reloaded.git

Test post-receive without pushing

The post-receive is a simple script. We can simulate the invocation after a push by simply feeding it the correct input in stdin.

echo "$FROM_ID $TO_ID master" | ./hooks/post-receive

To recover the IDs required to replace the two variables in the script above, we can use git log and request the last two commits this way

# git log -2 --format=oneline --reverse
be030379bc039a6138d714790285b776dad21e31 Additional entries
70f86bde545d8f243aed32491ef3690b6c4ea19b Changed text

The two IDs are correctly ordered and can be fed to the script:

echo "be030379bc039a6138d714790285b776dad21e31 70f86bde545d8f243aed32491ef3690b6c4ea19b master" | ./hooks/post-receive

Bare cloning and mirroring

To clone a repository in bare form

git clone --bare proto://address.of/your/repository.git

To push a repository to a bare mirror

git push --mirror proto://address.of/mirror/repository.git

Allow merging unrelated histories

git pull --allow-unrelated-histories

Back to Menu