<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Sarath P M</title>
    <description>The latest articles on Forem by Sarath P M (@sarath-pm).</description>
    <link>https://forem.com/sarath-pm</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F869850%2F2f2d04ee-4ebc-4138-b00c-51ef8695ec8a.jpg</url>
      <title>Forem: Sarath P M</title>
      <link>https://forem.com/sarath-pm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sarath-pm"/>
    <language>en</language>
    <item>
      <title>Secure CloudSQL Connectivity with Google Cloud SQL Auth Proxy as Systemd</title>
      <dc:creator>Sarath P M</dc:creator>
      <pubDate>Sun, 21 Jan 2024 05:54:10 +0000</pubDate>
      <link>https://forem.com/sarath-pm/secure-cloudsql-connectivity-with-google-cloud-sql-auth-proxy-as-systemd-3gg2</link>
      <guid>https://forem.com/sarath-pm/secure-cloudsql-connectivity-with-google-cloud-sql-auth-proxy-as-systemd-3gg2</guid>
      <description>&lt;p&gt;Tired of juggling database security and accessibility?  Enter Google Cloud SQL Auth Proxy, your gateway to secure and effortless connections to your Google Cloud SQL instances, without exposing external IPs. This guide will guide you through installing and configuring Cloud SQL Auth Proxy as Systemd on Ubuntu in two ways.&lt;/p&gt;

&lt;p&gt;Unfamiliar with Cloud SQL Proxy? No worries! Check out the official documentation here: &lt;a href="https://cloud.google.com/sql/docs/mysql/sql-proxy"&gt;https://cloud.google.com/sql/docs/mysql/sql-proxy&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. One-Click Script Installation:
&lt;/h2&gt;

&lt;p&gt;This method is perfect for speed and simplicity. Just grab the script, customize it with your details, and run it!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Git Repo: &lt;a href="https://github.com/sarath-pm/gcp-cloudsqlproxy-systemd"&gt;https://github.com/sarath-pm/gcp-cloudsqlproxy-systemd&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Step 1: Preparing the Environment:
&lt;/h3&gt;

&lt;p&gt;To kickstart the process, ensure your Ubuntu environment is up-to-date by running the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;wget &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Clone the magic script:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/sarath-pm/gcp-cloudsqlproxy-systemd.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Navigate and Run the script:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;gcp-cloudsqlproxy-systemd
&lt;span class="nb"&gt;chmod&lt;/span&gt; +x cloudsqlproxy.sh
./cloudsqlproxy.sh INSTANCE_CONNECTION_NAME PORT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Check for Permission Slips: Make Sure Your Service Account has required roles to Access Cloud SQL&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's it!  If the cloudsqlproxy service is running, you've successfully installed Cloud SQL Auth Proxy.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Manual Installation for the Savvy:
&lt;/h2&gt;

&lt;p&gt;Prefer to take the scenic route? This method gives you more control over the configuration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Preparing the Environment:
&lt;/h3&gt;

&lt;p&gt;To kickstart the process, ensure your Ubuntu environment is up-to-date by running the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;wget
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Downloading and Installing Cloud SQL Proxy:
&lt;/h3&gt;

&lt;p&gt;Now, let's get the Google Cloud SQL Proxy and make it executable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 &lt;span class="nt"&gt;-O&lt;/span&gt; cloud_sql_proxy
&lt;span class="nb"&gt;chmod&lt;/span&gt; +x cloud_sql_proxy
&lt;span class="nb"&gt;sudo cp&lt;/span&gt; ~/cloud_sql_proxy /usr/local/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands fetch the proxy binary, make it executable, and place it in the &lt;code&gt;/usr/local/bin&lt;/code&gt; directory for easy access.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Creating the Systemd Service:
&lt;/h3&gt;

&lt;p&gt;Next, we create a systemd service unit file for the Cloud SQL Proxy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;vi /lib/systemd/system/cloudsqlproxy.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following content, replacing the placeholders &lt;code&gt;INSTANCE_CONNECTION_NAME&lt;/code&gt; and &lt;code&gt;PORT&lt;/code&gt; with your actual values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="nn"&gt;[Unit]&lt;/span&gt;
&lt;span class="py"&gt;Description&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;Google Cloud SQL Auth Proxy&lt;/span&gt;

&lt;span class="nn"&gt;[Service]&lt;/span&gt;
&lt;span class="py"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;simple&lt;/span&gt;
&lt;span class="py"&gt;WorkingDirectory&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/usr/local/bin&lt;/span&gt;
&lt;span class="py"&gt;ExecStart&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/usr/local/bin/cloud_sql_proxy -instances=INSTANCE_CONNECTION_NAME=tcp:0.0.0.0:PORT&lt;/span&gt;
&lt;span class="py"&gt;Restart&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;always&lt;/span&gt;
&lt;span class="py"&gt;StandardOutput&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;journal&lt;/span&gt;
&lt;span class="py"&gt;User&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;root&lt;/span&gt;

&lt;span class="nn"&gt;[Install]&lt;/span&gt;
&lt;span class="py"&gt;WantedBy&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;multi-user.target&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Ensure your compute engine bears the necessary Service Account permissions to access Cloud SQL. Alternatively, append&lt;/em&gt; &lt;code&gt;credential_file=/path/default-account.json &amp;amp;&lt;/code&gt; &lt;em&gt;to the&lt;/em&gt; &lt;code&gt;ExecStart&lt;/code&gt; &lt;em&gt;line in the&lt;/em&gt; &lt;code&gt;cloudsqlproxy.service&lt;/code&gt; &lt;em&gt;file, as illustrated below:&lt;/em&gt;&lt;/p&gt;


&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="py"&gt;ExecStart&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/usr/local/bin/cloud_sql_proxy -instances=INSTANCE_CONNECTION_NAME=tcp:0.0.0.0:PORT -credential_file=/path/default-account.json &amp;amp;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

&lt;p&gt;This configuration specifies the service details, working directory, and the Cloud SQL instance connection parameters.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Reloading and Starting the Service:
&lt;/h3&gt;

&lt;p&gt;After creating the systemd service, reload the systemd manager configuration, start and enable the Cloud SQL Auth Proxy service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl daemon-reload
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl start cloudsqlproxy
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;cloudsqlproxy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: Verification:
&lt;/h3&gt;

&lt;p&gt;To ensure everything is running smoothly, check the status of the service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl status cloudsqlproxy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the service is active and running, congratulations! You've conquered manual installation!&lt;/p&gt;




&lt;h2&gt;
  
  
  Let's Connect!
&lt;/h2&gt;

&lt;p&gt;Now, your applications can waltz effortlessly with your Google Cloud SQL database! Don't hesitate to leave questions or share your own adventures with Cloud SQL Auth Proxy in the comments below. Happy connecting! ✨&lt;br&gt;
&lt;strong&gt; 🌐 &lt;a href="https://www.linkedin.com/in/sarath-p-m"&gt;LinkedIn&lt;/a&gt;&lt;br&gt;
 🚀 &lt;a href="https://github.com/sarath-pm"&gt;GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>googlecloud</category>
      <category>database</category>
      <category>security</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Deploying Adminer on Google App Engine (GAE) with Private and Public IP Connectivity</title>
      <dc:creator>Sarath P M</dc:creator>
      <pubDate>Fri, 17 Nov 2023 14:26:17 +0000</pubDate>
      <link>https://forem.com/sarath-pm/deploying-adminer-on-google-app-engine-gae-with-private-and-public-ip-connectivity-26bm</link>
      <guid>https://forem.com/sarath-pm/deploying-adminer-on-google-app-engine-gae-with-private-and-public-ip-connectivity-26bm</guid>
      <description>&lt;h2&gt;
  
  
  Adminer
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.adminer.org/"&gt;Adminer&lt;/a&gt; (formerly phpMinAdmin) is a full-featured database management tool written in PHP. Unlike phpMyAdmin, it offers a single-file deployment, making it highly convenient for target servers. Adminer supports various databases, including MySQL, MariaDB, PostgreSQL, SQLite, MS SQL, Oracle, Elasticsearch, MongoDB, and more through plugins. Its simplicity and broad compatibility make Adminer an efficient choice for database management.&lt;/p&gt;

&lt;p&gt;This guide will walk you through deploying Adminer on Google App Engine standard environment, allowing you to connect to SQL servers using both Private and Public IPs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before getting started, make sure you have the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Google Cloud Platform account.&lt;/li&gt;
&lt;li&gt;Basic knowledge of GCP services.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Set up a GCP Project
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open the &lt;a href="https://console.cloud.google.com/"&gt;Google Cloud Console&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Create a new project or select an existing one.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 2: Enable App Engine API
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to the &lt;code&gt;App Engine&lt;/code&gt; section in the Google Cloud Console.&lt;/li&gt;
&lt;li&gt;Enable App Engine for your project if it's not already enabled.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 3: Download the Adminer
&lt;/h2&gt;

&lt;p&gt;You'll deploy &lt;a href="https://www.adminer.org/en/"&gt;Adminer&lt;/a&gt; as a service of your App Engine Standard application, so you must download the source code for Adminer. Follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the Cloud Shell Terminal by navigating to the &lt;code&gt;Cloud Shell&lt;/code&gt;  or press &lt;code&gt;g+s&lt;/code&gt; to open the Cloud Shell using the shortcut. Alternatively, you can use the Google Cloud SDK installed on your local machine.&lt;/li&gt;
&lt;li&gt;In the terminal, create a new directory named &lt;code&gt;Adminer&lt;/code&gt; and enter the following commands to download &lt;code&gt;Adminer version 4.8.1&lt;/code&gt; and save it as &lt;code&gt;index.php&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;Adminer
&lt;span class="nb"&gt;cd &lt;/span&gt;Adminer
wget https://github.com/vrana/adminer/releases/download/v4.8.1/adminer-4.8.1.php &lt;span class="nt"&gt;-O&lt;/span&gt; index.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To use a different version of Adminer, use the links to available versions on the &lt;a href="https://github.com/vrana/adminer/releases"&gt;Adminer Downloads page&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Prepare the Adminer files for deployment
&lt;/h2&gt;

&lt;p&gt;In the directory that you created, named &lt;code&gt;Adminer&lt;/code&gt;, create a new file named &lt;code&gt;app.yaml&lt;/code&gt; file for App Engine configuration:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For Public IP connection to SQL server use the below &lt;code&gt;app.yaml&lt;/code&gt; file.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;adminer&lt;/span&gt;
&lt;span class="na"&gt;runtime&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;php82&lt;/span&gt;

&lt;span class="na"&gt;handlers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/.*&lt;/span&gt;
  &lt;span class="na"&gt;script&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;index.php&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For Private IP connection to SQL server use the below &lt;code&gt;app.yaml&lt;/code&gt; file.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;adminer&lt;/span&gt;
&lt;span class="na"&gt;runtime&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;php82&lt;/span&gt;

&lt;span class="na"&gt;handlers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/.*&lt;/span&gt;
  &lt;span class="na"&gt;script&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;index.php&lt;/span&gt;

&lt;span class="na"&gt;vpc_access_connector&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
 &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;projects/PROJECT_ID/locations/REGION/connectors/CONNECTOR_NAME&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Where &lt;code&gt;PROJECT_ID&lt;/code&gt; is your Google Cloud project ID, &lt;code&gt;REGION&lt;/code&gt; is the region your connector is in, and &lt;code&gt;CONNECTOR_NAME&lt;/code&gt; is the name of your &lt;a href="https://cloud.google.com/appengine/docs/standard/connecting-vpc#console"&gt;Serverless VPC Access connector&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you are deploying Adminer as the first and only application in App Engine, change the value for service from Adminer to default.&lt;/p&gt;

&lt;p&gt;Normally, you would deploy phpMyAdmin as a service of an existing application and provide a name for the service. However, if you haven't yet deployed an application, then you are required to use the service name "default". That's fine for the purposes of this tutorial if you're trying out phpMyAdmin on App Engine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Deploy the application to App Engine:
&lt;/h2&gt;

&lt;p&gt;Deploy the application by running the following command from within the Adminer directory where your &lt;code&gt;app.yaml&lt;/code&gt; file is located:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud app deploy &lt;span class="nt"&gt;--version&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;VERSION_ID
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Replace &lt;code&gt;VERSION_ID&lt;/code&gt; with the latest version&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Step 5: Log in to Adminer
&lt;/h2&gt;

&lt;p&gt;Once the deployment is complete, you can access Adminer in your web browser at &lt;br&gt;
&lt;code&gt;https://adminer-dot-[YOUR_APP_ID].appspot.com&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 6: Clean Up (Optional)
&lt;/h2&gt;

&lt;p&gt;If you want to clean up App Engine resources after testing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud app versions delete VERSION_ID
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Replace &lt;code&gt;VERSION_ID&lt;/code&gt; with the version you want to delete&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations! You have successfully deployed Adminer on Google App Engine. Access your Adminer instance by navigating to the provided App Engine URL, and start managing your databases with ease.&lt;/p&gt;

&lt;p&gt;Feel the freedom to tailor the deployment to suit your unique specifications. Enjoy your coding adventures, and don't forget to show some love for open source!&lt;/p&gt;

&lt;p&gt;Extend your support to the ingenious mind behind Adminer, &lt;strong&gt;Jakub Vrána&lt;/strong&gt;, by contributing to the dance of creativity on &lt;strong&gt;&lt;a href="https://www.patreon.com/jakubvrana"&gt;Patreon&lt;/a&gt;&lt;/strong&gt;. Your generosity keeps the rhythm alive!&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Connect!
&lt;/h2&gt;

&lt;p&gt;Feel the vibe and join the conversation. Your questions, ideas, and thoughts are not just welcomed but cherished. 🚀&lt;br&gt;
&lt;strong&gt; 🌐 &lt;a href="https://www.linkedin.com/in/sarath-p-m"&gt;LinkedIn&lt;/a&gt;&lt;br&gt;
 🚀 &lt;a href="https://github.com/sarath-pm"&gt;GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>googlecloud</category>
      <category>devops</category>
      <category>sql</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Git Cheatsheet</title>
      <dc:creator>Sarath P M</dc:creator>
      <pubDate>Sat, 03 Sep 2022 13:35:05 +0000</pubDate>
      <link>https://forem.com/sarath-pm/git-cheatsheet-414e</link>
      <guid>https://forem.com/sarath-pm/git-cheatsheet-414e</guid>
      <description>&lt;p&gt;Hey there, fabulous folks! Behold, a swift and snappy cheat sheet for your Git command adventures:&lt;/p&gt;

&lt;h2&gt;
  
  
  git config
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Setup author name and mail to be used for all commits in current repository, Devs commonly use &lt;code&gt;--global flag&lt;/code&gt; to set config options for current user.&lt;br&gt;
&lt;code&gt;git config --global user.name "username"&lt;/code&gt;&lt;br&gt;
&lt;code&gt;git config --global user.email "usermail@example.com"&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  git clone
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Clone the remote repository with HTTPS or with SSH. This should create a new child directory for the project sources.&lt;br&gt;
&lt;code&gt;git clone &amp;lt;REPO CLONE URL&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  git status
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Shows the status of your current branch. It will tell you which files you have modified, which files are stages for commit and which files are not. It will also let you know if your local branch is behind, or not up to date with, its remote tracking branch. This command is particularly useful in combination with &lt;code&gt;git add&lt;/code&gt; when you only want to commit certain files.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  git branch
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Create a branch, or show a list of local or remote branches. With git branch, you can add options to do branch-related things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git branch new-branch-name&lt;/code&gt;: Create a branch off of the current branch named &lt;code&gt;new-branch-name&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-d or --delete&lt;/code&gt;: Delete a branch. e.g. &lt;code&gt;git branch -d feature-branch-name&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-D&lt;/code&gt;: Force delete a branch. This is used when you want to delete a branch that has changes that weren't pushed to the server or merged. e.g. &lt;code&gt;git branch -D feature-branch-name&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-a or --all&lt;/code&gt;: Display all local and remote-tracking branches.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  git fetch
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Fetches branches from the server, along with their history and information. You can also use &lt;code&gt;git fetch origin&lt;/code&gt; to update your remote-tracking branches.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  git pull
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Update your working directory by performing a git fetch, followed by a git merge. This is useful if you want to bring your branch up to date with the remote-tracking branch.&lt;br&gt;
You can also use the &lt;code&gt;--rebase&lt;/code&gt; option to perform a rebase rather than a merge.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  git checkout
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;This command has a few functions. It can be used to create a new branch off of the current branch, it can be used to checkout a branch from the server, or switch to another branch.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git checkout develop&lt;/code&gt;: you will use this a lot. It will switch you from whatever branch you are currently in to the &lt;code&gt;develop&lt;/code&gt; branch. If you have changes in your current branch, you will need to either stash them or undo your changes before you switch branches.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git checkout branch-on-server&lt;/code&gt;: If you want to work on another persons branch (assuming they already pushed their branch to the remote repository), you can use this command to create a copy of the branch on your local machine. You will need to do &lt;code&gt;git fetch&lt;/code&gt; first to grab the information about the branch.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git checkout -b new-branch-name&lt;/code&gt;: create a new branch off of the current branch and switch to that branch. If you are in &lt;code&gt;develop&lt;/code&gt;, this will create a new branch from develop. This command is synonymous to &lt;code&gt;git branch new-branch-name &amp;amp;&amp;amp; git checkout new-branch-name&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  git add
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;You made changes to your branch, and you want to stage your changes for committing. You will need to add them to what is known as the &lt;code&gt;index&lt;/code&gt;. Here are two ways to do this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git add /filepath/file.f&lt;/code&gt;: this will add the single file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git add .&lt;/code&gt;: this will add all the changed files. Be careful here; make sure you aren't adding unwanted changes by reviewing your changes using &lt;code&gt;git status&lt;/code&gt;. If you accidentally staged unwanted files, take a look at &lt;code&gt;git reset&lt;/code&gt; described below.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  git commit
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;You want to make a commit! Awesome! Here's how you do it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git commit&lt;/code&gt;: This will make a commit of the files you have staged using &lt;code&gt;git add&lt;/code&gt;, and will open a VIM editor (or whichever editor you have configured in your .gitconfig) to enter your commit message.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git commit --amend&lt;/code&gt;: This is used to modify the most recent commit. It combines changes in the staging environment with the latest commit, and creates a new commit. This new commit replaces the latest commit entirely.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git commit -a&lt;/code&gt;: This will make a commit and add all changed files, and will open an editor to enter your commit message. This is the same as doing &lt;code&gt;git add . &amp;amp;&amp;amp; git commit&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git commit -m "commit message"&lt;/code&gt;: Skip the editor and put your entire message in the command line!&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git commit -a -m "commit message"&lt;/code&gt;: Combine them all! Fab.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  git push
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Once you make a commit, you will need to push your changes to the server to make it visible to the world. Once you push, your branch and commit(s) will be visible to others.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git push branch-name&lt;/code&gt; or &lt;code&gt;git push origin HEAD&lt;/code&gt;: Push your branch upstream. You can use either version; using origin HEAD is simply a more verbose way of pushing. It signifies you are pushing the tip (HEAD) your branch to the same name on the remote &lt;code&gt;origin&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git push origin -f branch-name&lt;/code&gt; or &lt;code&gt;git push origin +branch-name&lt;/code&gt;: ❗ ❗ ❗ &lt;strong&gt;BE CAREFUL: This is a potentially scary command, and you should only use it if you really know what you are doing. It will overwrite the branch you specified on the remote repository with your local copy of the branch.&lt;/strong&gt; ❗ ❗ ❗
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  git log
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Show the history of all branches and their commits. Useful for seeing the most recent commit and getting commit hashes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git log&lt;/code&gt;: Show all commits on this branch, along with the commit hash, author, date and message.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git log --oneline&lt;/code&gt;: Show a simplified version of the above command, showing only the commit hash and commit message.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git log --graph&lt;/code&gt;: Show a graph of the commit history for your branch. (AWESOME)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git log --max-count &amp;lt;n&amp;gt;&lt;/code&gt;: Limit the number of commits shown.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git log --oneline --graph --max-count 50&lt;/code&gt;: Combined them all! Woo!&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  git rebase
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.stack.imgur.com%2F5yRg3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.stack.imgur.com%2F5yRg3.png"&gt;&lt;/a&gt;&lt;br&gt;
Rebasing is a bit more advanced, but incredibly useful when you need it. When you perform a rebase, you are changing the base of your branch. In essence, a rebase will look at each commit on your branch and update the code to make it seem like you've been working off the new base all along. Sometimes, a rebase will barf if it encounters a situation in which it tries to update a piece of code that you have already modified. In this case, it doesn't know which version of the code to use, so it leaves it to you to resolve them manually.&lt;br&gt;
Although they have similar uses, a rebase differs from a merge in that a rebase updates your branch by tweaking each commit, and merge will update your branch by creating a new commit at the tip of your branch. Usually, there are standards and practices employed in a project or team around which method is preferred. Have a discussion with your team about which workflow they prefer.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  git stash
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Stashing allows you to save your current unstaged changes and bring your branch back to an unmodified state. When you stash, your changes are pushed onto a stack. This is especially useful if you need to quickly switch to another branch without having to commit your incomplete changes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git stash&lt;/code&gt;: stash your unstaged changes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash pop&lt;/code&gt;: unstash your changes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash drop&lt;/code&gt;: drop your stashed changes. Careful, you will lose your changes!&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash push &amp;lt;path&amp;gt;&lt;/code&gt;: stash a single file&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash -m &amp;lt;message&amp;gt;&lt;/code&gt;: add a message to your stash&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  git reset
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Git reset is used to unstage files or remove commits. It does so by changing what the tip of the branch (HEAD) points to.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HEAD: Represents the tip of your branch.&lt;/li&gt;
&lt;li&gt;Index: Serves as the staging area, proposing changes for the next commit.&lt;/li&gt;
&lt;li&gt;Working Directory: The location of files on your disk. 
There are three reset modes: &lt;code&gt;--soft&lt;/code&gt;, &lt;code&gt;--mixed&lt;/code&gt; (default), and &lt;code&gt;--hard&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--soft&lt;/code&gt;: Unstages changes but keeps commit history intact.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--mixed&lt;/code&gt;: Adjusts the staging area without modifying the working directory.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--hard&lt;/code&gt;: Alters both the staging area and working directory.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Undo &lt;code&gt;git add&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git add .&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git reset -- file.html&lt;/code&gt; (unstages a single file)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git reset&lt;/code&gt; (unstages all changes)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Undo the Most Recent Commit:

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git commit -a -m "commit message"&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git reset --soft HEAD^&lt;/code&gt; (undoes the commit at the branch's tip)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git commit -a -m "new commit message"&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Undo a Commit Permanently:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git reset --hard HEAD~2&lt;/code&gt; (removes the last two commits, i.e., HEAD and HEAD^) 
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Let's Connect!
&lt;/h2&gt;

&lt;p&gt;Feel the vibe and join the conversation. Your questions, ideas, and thoughts are not just welcomed but cherished. 🚀&lt;br&gt;
&lt;strong&gt; 🌐 &lt;a href="https://www.linkedin.com/in/sarath-p-m" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;br&gt;
 🚀 &lt;a href="https://github.com/sarath-pm" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>programming</category>
      <category>github</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
