<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Git on Wojciech Marusiak IT Blog</title>
        <link>https://www.wojcieh.net/tags/git/</link>
        <description>Recent content in Git on Wojciech Marusiak IT Blog</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en-us</language>
        <lastBuildDate>Mon, 17 Mar 2025 00:00:00 +0000</lastBuildDate><atom:link href="https://www.wojcieh.net/tags/git/index.xml" rel="self" type="application/rss+xml" /><item>
        <title>Protect your Git secrets with Gitguardian</title>
        <link>https://www.wojcieh.net/protect-your-git-secrets-with-gitguardian/</link>
        <pubDate>Mon, 17 Mar 2025 00:00:00 +0000</pubDate>
        
        <guid>https://www.wojcieh.net/protect-your-git-secrets-with-gitguardian/</guid>
        <description>&lt;p&gt;&lt;img src=&#34;https://www.wojcieh.net/images/uploads/2025/03/gitguardian.webp&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;GitGuardian Logo&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;Since I started my journey with Hugo blogging platform migrating away from Wordpress several years ago I&amp;rsquo;ve been using Git more and more. It has been essential for me to save all critical work I am working on in Git. But as you are working it might happen that a &lt;strong&gt;secret&lt;/strong&gt; or two might be pushed to the Git repository. I am not guilty of that but as my process of learning and mastering the technology I found out that there is a possibility to protect your Git repositories even before pushing anything to the repository. In todays post I will show you how easily it is to use GitGurardian and prevent secrets leaking to public repositories.&lt;/p&gt;
&lt;p&gt;Luckily for us they provide free account with some nice stats.
&lt;img src=&#34;https://www.wojcieh.net/images/uploads/2025/03/gitguardian-free.webp&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;GitGuardian pricing&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;You can take a look at the &lt;a class=&#34;link&#34; href=&#34;https://www.gitguardian.com/pricing#plan-details&#34;  title=&#34;GitGuardian Pricing&#34;
     target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;detailed pricing&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;prerequisites&#34;&gt;Prerequisites
&lt;/h2&gt;&lt;p&gt;As a main prerequisite is Git repository. In my case I am using GitHub so I will show you how to configure it with GitHub.&lt;/p&gt;
&lt;h2 id=&#34;ggshield-installation&#34;&gt;ggshield installation
&lt;/h2&gt;&lt;!--adsense--&gt;
&lt;p&gt;At first in your local environment you need to install &lt;strong&gt;ggshiled&lt;/strong&gt;. It is a CLI tool which will will do the heavy work for you.&lt;/p&gt;
&lt;p&gt;Simply follow your operating system &lt;a class=&#34;link&#34; href=&#34;https://docs.gitguardian.com/ggshield-docs/getting-started#step-1-install-ggshield&#34;  title=&#34;ggshiled installation&#34;
     target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;installation guide&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Then you need to create GitGuardian account as you will need to authenticate via CLI.&lt;/p&gt;
&lt;h2 id=&#34;run-manual-repository-scan&#34;&gt;Run manual repository scan
&lt;/h2&gt;&lt;p&gt;Now as we have ggshield CLI installed we can initiate our scan.&lt;/p&gt;
&lt;p&gt;It is as simple as running the command &lt;code&gt;ggshield secret scan repo /path/to/the/repo&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Here is the result of my manual scan on one of my repositories.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://www.wojcieh.net/images/uploads/2025/03/ggshield-manual-scan.webp&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;ggshield manual scan&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;You can simply run this command on all of your repositories but if you have a lot of them it might take some time to do it.&lt;/p&gt;
&lt;h2 id=&#34;add-pre-commit-hooks-to-secure-your-repository&#34;&gt;Add pre commit hooks to secure your repository
&lt;/h2&gt;&lt;p&gt;It is possible to configure a pre commit hook in your Git repository so prior commit a ggshield CLI scann will be initiated.&lt;/p&gt;
&lt;p&gt;In order to do it you need to create a file called &lt;code&gt;.pre-commit-config.yaml&lt;/code&gt;. In tat file add following code&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;4
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;5
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;6
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;7
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-YAML&#34; data-lang=&#34;YAML&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nt&#34;&gt;repos&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;- &lt;span class=&#34;nt&#34;&gt;repo&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;l&#34;&gt;https://github.com/gitguardian/ggshield&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;rev&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;l&#34;&gt;v1.37.0&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;hooks&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;      &lt;/span&gt;- &lt;span class=&#34;nt&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;l&#34;&gt;ggshield-push&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;language_version&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;l&#34;&gt;python3&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;stages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;l&#34;&gt;pre-push]&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;You can check if there are some changes in this code as per &lt;a class=&#34;link&#34; href=&#34;https://docs.gitguardian.com/ggshield-docs/integrations/git-hooks/pre-push&#34;  title=&#34;pre commit installation guide&#34;
     target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;installation guide&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In order to add pre-commit we need to install it via Pip.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;pip install pre-commit
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Once installed and the file is created you can simply by running command.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;pre-commit install --hook-type pre-push
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;If installed successfully you will receive following output &lt;code&gt;pre-commit installed at .git/hooks/pre-push&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;After installing pre-commit before every push of code to Git repository it will be automatically scanned with &lt;strong&gt;ggshield&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;If everything is configured correctly your repository should be scanned prior to push.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://www.wojcieh.net/images/uploads/2025/03/automatic-ggshield-scan.webp&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;ggshield automatic scan&#34;
	
	
&gt;&lt;/p&gt;
&lt;h2 id=&#34;optional---scan-all-your-repositories&#34;&gt;Optional - Scan all your repositories
&lt;/h2&gt;&lt;p&gt;If you are ok with that you can grant GitGuardian permissions to scan your whole Git account. In my case I allowed this and several issues have been identified. Luckily for me all those affected repositories are private.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://www.wojcieh.net/images/uploads/2025/03/github-vulnerabilities.webp&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;Vulnerabilities found in GitHub&#34;
	
	
&gt;&lt;/p&gt;
&lt;h2 id=&#34;summary&#34;&gt;Summary
&lt;/h2&gt;&lt;p&gt;I hope you liked it and that this will help you to secure your Git repositories.&lt;/p&gt;</description>
        </item>
        
    </channel>
</rss>
