diff --git a/Mastering-Versioning/Git-Best-Practices-Adoption.md b/Mastering-Versioning/Git-Best-Practices-Adoption.md index 1d43e46..ca59c08 100644 --- a/Mastering-Versioning/Git-Best-Practices-Adoption.md +++ b/Mastering-Versioning/Git-Best-Practices-Adoption.md @@ -17,10 +17,7 @@ In this lab you will: just use `cd`: ```console - ~ $ cd myrepo - (no output) - - ~/myrepo $ git status + $ cd /git/myrepo && git status On branch main Your branch is up to date with 'origin/main'. @@ -34,8 +31,8 @@ In this lab you will: The `commit-msg` Git hook will be: ```console - ~/myrepo $ cat < .git/hooks/commit-msg - grep -q '^feat: \|^bug: ' \$1 &> /dev/null + $ cat < .git/hooks/commit-msg + echo "\$1" | grep -q '^feat: \|^bug: ' &> /dev/null if [ \$? -ne 0 ] then echo "[ERROR] Commit must start with 'feat:' or 'bug:'!" @@ -47,7 +44,7 @@ In this lab you will: And must be executable: ```console - ~/myrepo $ chmod -v +x .git/hooks/commit-msg + $ chmod -v +x .git/hooks/commit-msg mode of '.git/hooks/commit-msg' changed to 0755 (rwxr-xr-x) ``` @@ -55,9 +52,9 @@ In this lab you will: `.gitignore` and commit the modification: ```console - ~/myrepo $ echo 'id_rsa*' >> .gitignore + $ echo 'id_rsa*' >> .gitignore - ~/myrepo $ git add .gitignore && git commit -m "feat: ignore id_rsa key files" -m "This applies the best practice to exclude SSH private and public keys." + $ git add .gitignore && git commit -m "feat: ignore id_rsa key files" -m "This applies the best practice to exclude SSH private and public keys." [main 978602b] feat: ignore id_rsa key files 1 file changed, 1 insertion(+) ``` @@ -80,7 +77,7 @@ In this lab you will: Then Git LFS can be enabled with the `git lfs install` command: ```console - ~/myrepo $ git lfs install + $ git lfs install Updated Git hooks. Git LFS initialized. ``` @@ -88,21 +85,21 @@ In this lab you will: Then to track the `*.zip` files `git lfs track` should be used as follows: ```console - ~/myrepo $ git lfs track "*.zip" + $ git lfs track "*.zip" Tracking "*.zip" ``` This will create `.gitattributes`: ```console - ~/myrepo $ cat .gitattributes + $ cat .gitattributes *.zip filter=lfs diff=lfs merge=lfs -text ``` And a commit will add it to the repo: ```console - ~/myrepo $ git add .gitattributes && git commit -m "Enable LFS for zip files" -m "This is made to avoid large files to be stored in the repo" + $ git add .gitattributes && git commit -m "Enable LFS for zip files" -m "This is made to avoid large files to be stored in the repo" [main 308e38d] Enable LFS for zip files 1 file changed, 1 insertion(+) create mode 100644 .gitattributes @@ -111,19 +108,19 @@ In this lab you will: Now to check that everything is working, add a 10MB file sample: ```console - ~/myrepo $ dd if=/dev/zero of=myarchive.zip bs=1024 count=10000 + $ dd if=/dev/zero of=myarchive.zip bs=1024 count=10000 10000+0 records in 10000+0 records out 10240000 bytes (9.8MB) copied, 0.058306 seconds, 167.5MB/s - ~/myrepo $ du -sh myarchive.zip + $ du -sh myarchive.zip 9.8M myarchive.zip ``` And check the actual size of the `.git` directory: ```console - ~/myrepo $ du -sh .git + $ du -sh .git 864.0K .git ``` @@ -132,7 +129,7 @@ In this lab you will: the path where the object is stored is different: ```console - ~/myrepo $ find .git -size +50 + $ find .git -size +50 .git/lfs/objects/31/e0/31e00e0e4c233c89051cd748122fde2c98db0121ca09ba93a3820817ea037bc5 ``` @@ -141,13 +138,13 @@ In this lab you will: 5. To test the `commit-msg` Git hook: ```console - ~/myrepo $ echo "A test for the commit-msg hook" >> First.txt + $ echo "A test for the commit-msg hook" >> First.txt (no output) - ~/myrepo $ git add First.txt + $ git add First.txt (no output) - ~/myrepo $ git commit -m "Test commit-msg hook" -m "Extended description of the commit" + $ git commit -m "Test commit-msg hook" -m "Extended description of the commit" [ERROR] Commit must start with 'feat:' or 'bug:'! ``` @@ -155,7 +152,7 @@ In this lab you will: `myrepo`: ```console - ~/myrepo $ ssh-keygen -f ./id_rsa + $ ssh-keygen -f ./id_rsa Generating public/private ed25519 key pair. Enter passphrase (empty for no passphrase): Enter same passphrase again: @@ -181,7 +178,7 @@ In this lab you will: return a list that is excluding `id_rsa*` files: ```console - ~/myrepo $ git status + $ git status On branch main Your branch is up to date with 'origin/main'. @@ -195,12 +192,12 @@ In this lab you will: hook preventing it, and since we don't care, we can safely `checkout` it: ```console - ~/myrepo $ git reset && git checkout First.txt + $ git reset && git checkout First.txt Unstaged changes after reset: M First.txt Updated 1 path from the index - ~/myrepo $ git status + $ git status On branch main Your branch is up to date with 'origin/main'. diff --git a/Mastering-Versioning/Git-Hooks.md b/Mastering-Versioning/Git-Hooks.md index 621ffe1..bb1e985 100644 --- a/Mastering-Versioning/Git-Hooks.md +++ b/Mastering-Versioning/Git-Hooks.md @@ -95,7 +95,7 @@ In this lab you will: ```console $ cat < .git/hooks/commit-msg - grep -q '^feat: \|^bug: ' \$1 &> /dev/null + echo "\$1" | grep -q '^feat: \|^bug: ' &> /dev/null if [ \$? -ne 0 ] then echo "[ERROR] Commit must start with 'feat:' or 'bug:'!"