<?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>DEV Community: Guroosh</title>
    <description>The latest articles on DEV Community by Guroosh (@guroosh).</description>
    <link>https://dev.to/guroosh</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%2F1957777%2F112bd8f3-74fa-49b3-ae4a-4e69f4e1b108.jpeg</url>
      <title>DEV Community: Guroosh</title>
      <link>https://dev.to/guroosh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/guroosh"/>
    <language>en</language>
    <item>
      <title>Beyond the Password: Modern Authentication Explained</title>
      <dc:creator>Guroosh</dc:creator>
      <pubDate>Thu, 04 Jun 2026 10:28:59 +0000</pubDate>
      <link>https://dev.to/guroosh/beyond-the-password-modern-authentication-explained-pin</link>
      <guid>https://dev.to/guroosh/beyond-the-password-modern-authentication-explained-pin</guid>
      <description>&lt;p&gt;Authentication is simply the act of proving who you are when accessing a resource on the internet. At its most basic, it begins when a user signs up and creates a password, which is then used to verify their identity every time they log in. Over time, this simple model is extended to handle more secure, reliable, and flexible ways of authenticating users.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo88sx944jlvejaigtwwa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo88sx944jlvejaigtwwa.png" width="799" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Password based Authentication
&lt;/h2&gt;

&lt;p&gt;When a user signs up or log in, a password get stored into the system which raise a lot of security questions: How are your passwords stored? What if the system’s database is compromised?&lt;/p&gt;

&lt;p&gt;So let’s dive into how passwords should be handled when building a basic authentication flow.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Passwords should be stored in the user table and mapped to a unique identifier such as a username or email, but they should never be stored as plain text. Instead, they should always be stored as a hashed value.&lt;/li&gt;
&lt;li&gt;Using hashes introduces a simple problem, for a specific algorithm — the same password will always produce the same hash, for example a common password like password will always give the the same hash &lt;code&gt;5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8&lt;/code&gt; when using &lt;a href="https://emn178.github.io/online-tools/sha256.html" rel="noopener noreferrer"&gt;sha256&lt;/a&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"password"&lt;/span&gt;
password

&lt;span class="nv"&gt;$ &lt;/span&gt;SHA256&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"password"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;These well-known hashes can be easily recognized using pre-computed lists, allowing attackers to reverse-engineer common passwords — Rainbow Table Attack.&lt;/li&gt;
&lt;li&gt;To prevent this, a &lt;strong&gt;salt&lt;/strong&gt; can be used. A salt is a randomly generated string created when a password is set or updated and is stored alongside the user’s record and hashed password, e.g.:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;id | username | salt | password_hash | ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The final stored value for &lt;code&gt;password_hash&lt;/code&gt; is created by combining the password with the user’s salt before hashing it:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;password_hash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;salt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This ensures that even common passwords result in unique hashes and cannot be reverse-engineered without knowing the original password.&lt;/li&gt;
&lt;li&gt;When a user logs in, the same process is repeated to verify a login. The entered password along with the user’s &lt;code&gt;salt&lt;/code&gt; is converted to a hashed value and the result is compared to the existing &lt;code&gt;password_hash&lt;/code&gt; to verify the user’s identity.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  From Passwords to Ongoing Access
&lt;/h3&gt;

&lt;p&gt;Relying only on passwords would make browsing the web extremely frustrating. Imagine having to enter your username and password every time you want to watch a movie on Netflix, check your messages, or simply refresh a webpage. Clearly, that is not how modern applications work.&lt;/p&gt;

&lt;p&gt;The reason you don’t have to log in again and again is because after a successful login your browser stores a small piece of information that helps the server recognize you on future requests.&lt;/p&gt;

&lt;p&gt;When you log in for the first time, the server doesn’t just grant access; it also returns a special value to the browser. This value is saved in the browser’s local storage and used on subsequent requests, allowing the server to verify your identity without needing your password.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Imagine this as the temporary wristband given to individuals when entering a private event. The wristband grants you temporary access for the day to different areas within the event, without requiring you to show your ticket again.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;At this point, you might be wondering:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How does the server create this special value?&lt;/li&gt;
&lt;li&gt;How does the server know which user it belongs to?&lt;/li&gt;
&lt;li&gt;Why use this approach at all — why not just store the username and password directly in the browser?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s start with the simplest one: why not store usernames and passwords directly in the browser? Because if someone gains access to your browser — through device access or a scripting attack, they would immediately have full control over your account. Since passwords are long-lived secrets, they should never be stores directly in the browser.&lt;/p&gt;

&lt;p&gt;In contrast, the value returned after login is limited in scope and lifetime. Even if it is stolen, it typically allows access only for a short period and does not reveal your actual account credentials.&lt;/p&gt;

&lt;p&gt;So where does the server keep track of this information, and how does it validate future requests? This is where two common approaches come into play:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Session based authentication&lt;/li&gt;
&lt;li&gt;Token based authentication&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fajiwf6qkc25wc23z3uxj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fajiwf6qkc25wc23z3uxj.png" alt="Session-based vs Token-based Authentication" width="799" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Session-based vs Token-based Authentication&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Session-based Authentication
&lt;/h2&gt;

&lt;p&gt;In session-based authentication, when a user logs in successfully, the server creates a session for that user and generates a unique session ID. This session ID is stored by the server, in either a database or in-memory store.&lt;/p&gt;

&lt;p&gt;The server then sends the session ID back to the browser in a cookie, which the browser can use for future requests. Using this approach, the user needs to enter their password only once during login or again when the session expires.&lt;/p&gt;

&lt;p&gt;With this approach, the actual user data and authentication information remain on the server. The session ID stored on the browser is only a temporary identifier.&lt;/p&gt;

&lt;p&gt;But what happens if someone steals the session ID? Since a session ID represents an authenticated user, stealing it can temporarily grant access to the account. To limit the impact, the backend system must provide mechanisms to invalidate existing sessions, such as a &lt;strong&gt;Log out everywhere&lt;/strong&gt; option which terminates all active sessions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pros
&lt;/h3&gt;

&lt;p&gt;The main advantage of session-based authentication is that it allows long-lived sessions without exposing your permanent credentials. This reduces the risk of losing access to an account permanently.&lt;/p&gt;

&lt;p&gt;For example, on platforms like Facebook, Netflix, or Gmail, you typically log in once and remain logged in for a long time on the same browser, without needing to re-enter your credentials.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cons
&lt;/h3&gt;

&lt;p&gt;The main drawbacks are infrastructure cost and operational overhead:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Developers must maintain a separate storage solution to keep session IDs mapped to user accounts.&lt;/li&gt;
&lt;li&gt;As discussed above, systems need a reliable way to invalidate all active sessions for a user, such as a &lt;strong&gt;Log out everywhere&lt;/strong&gt; feature.&lt;/li&gt;
&lt;li&gt;Every API call to the server requires an additional DB lookup to validate the session ID.&lt;/li&gt;
&lt;li&gt;Managing session storage introduces further challenges, including cleaning up expired sessions and synchronizing session data across regions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Token-based Authentication
&lt;/h2&gt;

&lt;p&gt;Given the operational complexity of stateful authentication, many systems move toward a stateless approach. This is where token-based authentication comes into play.&lt;/p&gt;

&lt;p&gt;In token-based authentication the information about the user’s identity is stored in the token itself — it is not a random hashed string. Instead this special kind of token contains information in plain site, this special token is a JSON Web Token (JWT) and usually called an &lt;strong&gt;access token&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A JWT relies on &lt;strong&gt;Digital Signatures&lt;/strong&gt;, which allow data to be signed using a secret key (e.g. HS256 algorithm). The signature enables the server to verify that the token was created by a trusted source and has not been tampered with.&lt;/p&gt;

&lt;p&gt;A JWT is made up of three parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The header&lt;/li&gt;
&lt;li&gt;The payload&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Encrypted&lt;/strong&gt; signature&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The header contains the metadata about the token which usually includes the encryption algorithm used to create the signature.&lt;/p&gt;

&lt;p&gt;The payload contains the actual data about the user, represented in JSON key-value pairs.&lt;/p&gt;

&lt;p&gt;The signature is created by encrypting the header and the payload using a secret key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SIGNATURE = ENCRYPT( HEADER + PAYLOAD )

JWT = HEADER + PAYLOAD + SIGNATURE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A complete JWT ends up looking like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0
.KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here each part of the token is base64-encoded and separated by a dot (&lt;code&gt;.&lt;/code&gt;) .&lt;/p&gt;

&lt;p&gt;You can view the decoded header and the payload of the above token by pasting the token in the website: &lt;a href="https://www.jwt.io" rel="noopener noreferrer"&gt;jwt.io&lt;/a&gt;. The website also shows if the token’s signature is valid or not by pasting the secret key used for creating the signature.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvcxtbwgzzy43n50vaeze.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvcxtbwgzzy43n50vaeze.png" alt="The token is valid and was signed by the secret key: **a-string-secret-at-least-256-bits-long**" width="798" height="251"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The token is valid and was signed by the secret key: &lt;strong&gt;a-string-secret-at-least-256-bits-long&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here is something interesting to try: if you modify the JSON payload slightly, re-encode it, and replace it in the token, the signature will no longer be valid — even if you use the same secret key. This is because the signature is created using both the header and the payload.&lt;/p&gt;

&lt;p&gt;This ensures two important things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The token was created and digitally signed by the server when the user mentioned in the payload authenticated.&lt;/li&gt;
&lt;li&gt;And more importantly — once a token is created, the token’s header and payload cannot be altered to create a fake or tampered token.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, tokens can still be stolen and reused to impersonate a user while they remain valid. Unlike sessions, there is no built-in way to invalidate all issued tokens at once.&lt;/p&gt;

&lt;p&gt;Because of this, tokens are typically short-lived and include an expiration time. Once expired, the server must reject them. This expiration is stored directly in the token’s payload:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"sub"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"123456789"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"John Doe"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"admin"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"iat"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1765221761&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"exp"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1765225361&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the &lt;strong&gt;exp&lt;/strong&gt; field specifies when the token will expire. The server uses this value to reject any token that is no longer valid.&lt;/p&gt;

&lt;p&gt;But what if an attacker steals the token and changes the expiry time to something far in the future? Well, that would require modifying the payload and as mentioned above, doing so would invalidate the signature and cause the token to be rejected by the server.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Imagine JWTs as the modern banknotes — where we can easily see the information: its value, the denomination, the currency and the issuing authority. All information is clearly visible to everyone but if it is tampered with or faked, its of no use.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This naturally raises another question: what happens after a token expires? Do users need to log in again? Short answer — No.&lt;/p&gt;

&lt;p&gt;If an access token expires every hour — which is a common practice in token-based authentication — forcing users to re-enter their username and password each time would be impractical.&lt;/p&gt;

&lt;p&gt;This is where a &lt;strong&gt;refresh token&lt;/strong&gt; comes into play.&lt;/p&gt;

&lt;h3&gt;
  
  
  Refresh Tokens
&lt;/h3&gt;

&lt;p&gt;A refresh token is a long-lived token whose sole purpose is to obtain a new access token. But how does that help, and what happens if a refresh token itself is stolen?&lt;/p&gt;

&lt;p&gt;Well, &lt;strong&gt;refresh tokens&lt;/strong&gt; are conceptually similar to the session IDs discussed earlier in the session-based authentication:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They are random, opaque strings and do not need to be JWTs.&lt;/li&gt;
&lt;li&gt;They are also stored and managed by the server, typically in a database.&lt;/li&gt;
&lt;li&gt;They are long-lived compared to access tokens.&lt;/li&gt;
&lt;li&gt;The server should have a &lt;strong&gt;Log out everywhere&lt;/strong&gt; mechanism to revoke all active refresh tokens associated to a user.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But this is how refresh tokens differ from session IDs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using a single session ID that is valid for months can introduce potential risks. In contrast, refresh tokens are long-lived compared to access tokens but still have an expiration ranging from a few hours to a day.&lt;/li&gt;
&lt;li&gt;When using session IDs, every API request required a database lookup request to validate the session ID. On the other hand, in token-based authentication, database access is only required when an access token needs to be refreshed. Once an access token is issued, no additional database lookups are required until it expires.&lt;/li&gt;
&lt;li&gt;Not every system needs refresh tokens. In scenarios that require higher security — such as banking websites or government portals, users are often required to enter their credentials on every login. These systems typically rely on very short-lived access tokens and do not issue refresh tokens at all.&lt;/li&gt;
&lt;li&gt;A common best practice with refresh tokens is to rotate them — since a refresh token’s purpose is to obtain new access tokens, it can be rotated each time a new access token is issued.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So finally here is a typical refresh token authentication flow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The user logs in using their username and password (credentials).&lt;/li&gt;
&lt;li&gt;After successful authentication, the server generates two tokens: an access token and a refresh token.&lt;/li&gt;
&lt;li&gt;The server returns both tokens to the browser.&lt;/li&gt;
&lt;li&gt;The browser stores the access token and refresh token securely (often using different storage mechanisms for each).&lt;/li&gt;
&lt;li&gt;The access token is sent with every authenticated request to prove the user’s identity.&lt;/li&gt;
&lt;li&gt;When the access token expires, the client sends the refresh token to the server to request a new access token.&lt;/li&gt;
&lt;li&gt;The server validates the refresh token and if valid, issues a new pair of access and refresh tokens.&lt;/li&gt;
&lt;li&gt;The old refresh token is invalidated, and the client updates its stored tokens with the newly issued ones.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This approach allows users to stay logged in without repeatedly entering their credentials, while still limiting the damage if any token is compromised.&lt;/p&gt;

&lt;h2&gt;
  
  
  Third-Party Login: OAuth and OIDC
&lt;/h2&gt;

&lt;p&gt;So far, we’ve seen that authentication usually starts with entering a username and password, and much of the complexity that follows is about reducing how often users need to re-enter those credentials. Another common way to achieve this is by using trusted third-party login providers to establish a user’s identity.&lt;/p&gt;

&lt;p&gt;Some of the most widely used third-party providers support &lt;strong&gt;OAuth&lt;/strong&gt; and &lt;strong&gt;OpenID Connect (OIDC)&lt;/strong&gt;, including Google, Facebook, and Microsoft. For simplicity, we’ll use Google as the example in this section.&lt;/p&gt;

&lt;p&gt;You’ve likely encountered Google-based login in many applications. The flow usually looks like this: you click the &lt;strong&gt;Sign in with Google&lt;/strong&gt; button and are redirected to a Google login page. After signing in, you’re asked to grant access to basic account information — typically your name, email address, and profile image. Once you click &lt;strong&gt;Allow&lt;/strong&gt;, you are redirected back to the original application.&lt;/p&gt;

&lt;p&gt;Under the hood, this flow is powered by &lt;strong&gt;OAuth&lt;/strong&gt; and &lt;strong&gt;OIDC&lt;/strong&gt;. OAuth provides a standardized way for an application to request access to a user’s data. OIDC builds on top of OAuth to add a verified identity layer, allowing the application to reliably know who the user is.&lt;/p&gt;

&lt;p&gt;Together, OAuth and OIDC enable third-party login by combining delegated access with secure user authentication.&lt;/p&gt;

&lt;p&gt;But what really happens behind the scenes? What information is exchanged between your application and Google? Lets walk through the flow step by step.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When you click &lt;strong&gt;Sign in with Google&lt;/strong&gt;, the frontend redirects the user to a Google-hosted consent screen. This redirect is made to Google’s authorization endpoint and includes a client_id, which uniquely identifies the application requesting access.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET https://accounts.google.com/o/oauth2/v2/auth
  ?client_id=YOUR_CLIENT_ID
  &amp;amp;redirect_uri=...
  &amp;amp;response_type=code
  &amp;amp;scope=...
  ...
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;After the user reviews the permissions and clicks &lt;strong&gt;Allow&lt;/strong&gt;, Google generates a short-lived &lt;strong&gt;authorization code (auth code)&lt;/strong&gt; and redirects the user back to the application’s configured callback URL, attaching this code to the request.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Redirect: https://yourapp.com/callback?code=AUTH_CODE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This auth code is similar to something we have already seen before — the &lt;strong&gt;session ID&lt;/strong&gt; or the &lt;strong&gt;refresh token&lt;/strong&gt; — but it is extremely short-lived and can be used only once. Google temporarily stores this code and associates it with the application’s &lt;code&gt;client_id&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Once the frontend receives the auth code, it forwards the code to the application’s server. The server then makes a second request to Google’s token endpoint. This request happens server-to-server over HTTPS, allowing the &lt;code&gt;client_secret&lt;/code&gt; to be safely included.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;POST https://oauth2.googleapis.com/token

  code=AUTH_CODE
  &amp;amp;client_id=YOUR_CLIENT_ID
  &amp;amp;client_secret=YOUR_CLIENT_SECRET
  &amp;amp;redirect_uri=...
  &amp;amp;grant_type=authorization_code
  ...
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Google validates the auth code against the &lt;code&gt;client_id&lt;/code&gt; and &lt;code&gt;client_secret&lt;/code&gt;. If everything checks out, the auth code is invalidated and deleted. Google then issues an &lt;strong&gt;ID token (JWT)&lt;/strong&gt; along with a pair of &lt;strong&gt;access and refresh tokens&lt;/strong&gt; and returns them to the application’s server.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The access and refresh token returned by Google are not important for the authentication process — these tokens can be used to get access to more Google services based on what permissions the client has.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;ID token&lt;/strong&gt; contains verified identity information about the user — such as name, email address, and profile picture. The server can use this information to create or look up a user record and then issue its own access and refresh tokens, following the same token-based authentication flow described earlier.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A natural question here is: why doesn’t Google directly issue an ID token right after the user clicks &lt;strong&gt;Allow&lt;/strong&gt;? Why go through the extra authorization code step at all?&lt;/p&gt;

&lt;p&gt;The reason is security. If Google were to return an ID token directly to the frontend, that token would be exposed in the browser. Any malicious script running on the page could read it and reuse it.&lt;/p&gt;

&lt;p&gt;More importantly, at that point Google would have no strong guarantee that the application receiving the token is actually legitimate. The &lt;strong&gt;authorization code flow&lt;/strong&gt; solves this by requiring a second, server-to-server exchange. Only the application’s server — where the &lt;code&gt;client_secret&lt;/code&gt; is securely stored — can exchange the authorization code for tokens.&lt;/p&gt;

&lt;p&gt;This step proves to Google that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the application is who it claims to be (via the client secret), and&lt;/li&gt;
&lt;li&gt;the authorization code was issued specifically for that application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By keeping the client secret out of the browser and requiring this verification step, Google ensures that ID tokens and access tokens are issued only to trusted servers, not directly to potentially compromised frontends.&lt;/p&gt;

&lt;p&gt;This is why the authorization code flow is the standard and recommended approach for OAuth/OIDC-based logins.&lt;/p&gt;

&lt;h2&gt;
  
  
  API Key Access
&lt;/h2&gt;

&lt;p&gt;When accessing a system’s APIs in an automated or programmatic way, logging in with user credentials or using user-bound tokens is often not practical. There is no interactive user, no browser, and no login flow. In such cases, systems provide &lt;strong&gt;API keys&lt;/strong&gt; as a way to authenticate in an automated way.&lt;/p&gt;

&lt;p&gt;For example, you can create API keys and secrets in AWS to access cloud services via code, or generate API keys in OpenAI to call its APIs programmatically.&lt;/p&gt;

&lt;p&gt;The way API keys work is not fundamentally different from what we’ve already discussed. An API key is a long, random string generated by the system and stored on the server, mapped to a user or application — similar to how a password is associated with a user account. In that sense, an API key can be thought of as a system-generated password.&lt;/p&gt;

&lt;p&gt;Just like passwords, API keys should not be stored in plain text. Instead, their hashed values are stored in the database. This is why many services show an API key only once at creation time and ask you to copy it immediately, because the system itself does not retain the original key — only its hash.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fffqkuicxac2tzaqwqnmo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fffqkuicxac2tzaqwqnmo.png" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A major risk with API keys is that if one is leaked — for example, an OpenAI API key — anyone who obtains it can make requests on your behalf, potentially leading to misuse or unexpected costs. To reduce this risk, some platforms issue &lt;strong&gt;API key and secret pairs&lt;/strong&gt;, where the secret is used to sign requests or is kept server-side, enabling stronger verification and more controlled access.&lt;/p&gt;

&lt;h2&gt;
  
  
  To Sum It Up
&lt;/h2&gt;

&lt;p&gt;At the core, modern authentication is about proving who someone is and safely remembering that trust over time. It helps systems let the right people and programs in, without repeatedly sharing sensitive information. The goal is to make access feel simple for legitimate users, while remaining difficult to exploit if something goes wrong.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Everything should be made as simple as possible, but not simpler.&lt;/p&gt;

&lt;p&gt;~Albert Einstein&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>security</category>
      <category>oauth</category>
      <category>programming</category>
      <category>jwt</category>
    </item>
    <item>
      <title>Git: Best Practices for Professionals</title>
      <dc:creator>Guroosh</dc:creator>
      <pubDate>Mon, 25 May 2026 14:16:10 +0000</pubDate>
      <link>https://dev.to/guroosh/git-best-practices-for-professionals-1ek5</link>
      <guid>https://dev.to/guroosh/git-best-practices-for-professionals-1ek5</guid>
      <description>&lt;p&gt;Developers working in fast-moving teams often deal with overlapping work, long-running features, and reviews that depend on clear and reliable history.&lt;/p&gt;

&lt;p&gt;This guide focuses on common Git problems developers face when working in teams and highlights the techniques that keep workflows stable, predictable, and easy to maintain.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgzzemz9ton093aldbrqp.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgzzemz9ton093aldbrqp.jpeg" width="799" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling Merge Conflicts the Right Way
&lt;/h2&gt;

&lt;p&gt;You created a Pull Request (PR) and when it’s time to merge it to &lt;code&gt;main&lt;/code&gt; you are hit with a Merge Conflict on the UI. Here’s how to handle the conflict efficiently and seamlessly.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Resolving the actual conflict will always be a manual task at the code level.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  1. Check your status when on your feature branch
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Checkout to the main branch — the one your PR needs to be merged to
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Then git pull to get latest main in your local
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git pull
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Switch back to the feature branch the PR is based on
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout feature-branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. Execute the Merge Command:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git merge main    &lt;span class="c"&gt;# (this tries to merge the main branch to the feature branch)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running the merge command you will get conflicts in certain files, these conflicts should replicate the original merge conflicts being faced in the Pull Request.&lt;/p&gt;

&lt;p&gt;Now the conflicts need to be merged manually and can incur code loss, which is fine if both the main and feature branches are pushed in origin.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status               
git add resolve files    &lt;span class="c"&gt;# add all the files with resolved code&lt;/span&gt;
git commit               &lt;span class="c"&gt;# just git commit; without the -m flag&lt;/span&gt;
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin HEAD  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running &lt;code&gt;git commit&lt;/code&gt; will auto create a Merge Commit so you don’t need to provide any custom message.&lt;/p&gt;

&lt;p&gt;After pushing to origin, the PR should not show any conflicts and the commit history in the feature branch should have a commit with an auto-merge message like this: &lt;code&gt;Merged PR 123: Updated the UI with new design&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reverting a Pushed Commit
&lt;/h2&gt;

&lt;p&gt;Often at times we push and merge a commit to the main branch but then things go wrong and we end up introducing unexpected bugs into production code.&lt;/p&gt;

&lt;p&gt;This is where you can safely revert the bad commit until the issue is identified. Here is how to do it safely:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Update your local repository
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout main
git pull
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. View the recent commits
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here find the bad commit and copy the commit hash, which should look something like this: c41975d1dae1cc69b16ad8892b8c77164e84ca39.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Revert the individual commit
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git revert c41975d1dae1cc69b16ad8892b8c77164e84ca39
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;git revert &amp;lt;commit-hash&amp;gt;&lt;/code&gt; automatically creates a commit message with a revert message:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Revert “Updated the UI with new design” This reverts commit c41975d1dae1cc69b16ad8892b8c77164e84ca39.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Verify and Push to main
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin HEAD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify using &lt;code&gt;git status&lt;/code&gt; that you are on the main branch and your local is a commit ahead of origin. &lt;code&gt;git push&lt;/code&gt; to push the reverted code changes to origin.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using stash the Right Way
&lt;/h2&gt;

&lt;p&gt;Imagine you are working on a feature and have some useful changes on local but you have to pull the latest code from &lt;code&gt;main&lt;/code&gt; to work on top of, so you do a &lt;code&gt;git pull&lt;/code&gt; but end up getting the following message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;error: Your local changes to the following files would be overwritten by merge:
    &amp;lt;file names&amp;gt;
Please commit your changes or stash them before you merge.
Aborting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here git already gives you a hint of what you need to do.&lt;/p&gt;

&lt;p&gt;Using &lt;code&gt;git stash&lt;/code&gt; the right way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash
git pull
git stash apply    &lt;span class="c"&gt;# this reapplies the latest stashed changes in your local&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; this might give you merge conflicts.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This can be unsafe if you forget to reapply the changes immediately and lose track of the stashed code, so it is recommended for only small changes.&lt;/p&gt;

&lt;p&gt;A safer approach for larger changes would be to ensure you checkout to a new branch and push your changes to origin. Which allows you to freely pull the latest code and merge it to your working branch without losing your code.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; this might also give you merge conflicts.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Resetting to a Previous Commit
&lt;/h2&gt;

&lt;p&gt;What if you are working locally and have a few bad commits which you want to get rid of.&lt;/p&gt;

&lt;p&gt;When can this happen:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You were resolving a merge conflict but end up with bad commits.&lt;/li&gt;
&lt;li&gt;You have some unwanted commits in your local which you do not want or even remember — can happen if you restart work on an old feature after a long time.&lt;/li&gt;
&lt;li&gt;Or you get the following message and git pull raises merge conflicts.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Your branch and 'origin/&amp;lt;branch&amp;gt;' have diverged,
and have 4 and 2 different commits each, respectively.
 (use "git pull" to merge the remote branch into yours)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are sure your local commits are unwanted or backed up, you can get rid of them by resetting your commit history by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD~
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;CAUTION: This command destroys your local commits permanently!&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This resets the local HEAD to one previous commit.&lt;/p&gt;

&lt;p&gt;If you have multiple local unwanted commits, you can run the command multiple times and sync cleanly using a &lt;code&gt;git pull&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD~
git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD~
git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD~
...
git pull
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will reset the HEAD multiple times to a stable commit and then you can sync with the origin with no issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cherry Picking
&lt;/h2&gt;

&lt;p&gt;Cherry-picking lets you take a specific commit from any branch and apply it onto another branch.&lt;/p&gt;

&lt;p&gt;It is a useful command which lets you pick up all changes in a commit from one branch to another, given that the 2 parent branches have similar history.&lt;/p&gt;

&lt;p&gt;Possible useful scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You fixed a bug on one branch e.g. “the dev branch”, and need the same fix to be applied on another branch e.g. “the release branch”.&lt;/li&gt;
&lt;li&gt;You accidentally committed changes to a wrong branch and want to move the commit to the correct branch.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is how to cherry-pick a commit safely from branch A to branch B:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. View the recent commits on branch A
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout branch-a
git log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here find the commit to copy and copy its hash.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Switch to branch B
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout branch-b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Apply the individual commit
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git cherry-pick c41975d1dae1cc69b16ad8892b8c77164e84ca39
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On a successful cherry pick you will get the following message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[main abc123] Fix login bug
 Date: Tue Dec 1 12:00:00 2020 +0200
 2 files changed, 10 insertions(+), 3 deletions(-)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After which it should be safe to push to origin.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hope this guide helps.&lt;/p&gt;

&lt;p&gt;Also, check out the guide &lt;a href="https://dev.to/guroosh/git-best-practices-for-beginners-1h3c"&gt;Best Git Practices for Beginners&lt;/a&gt; if you haven’t already.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>git</category>
      <category>productivity</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Git: Best Practices for Beginners</title>
      <dc:creator>Guroosh</dc:creator>
      <pubDate>Mon, 25 May 2026 14:03:41 +0000</pubDate>
      <link>https://dev.to/guroosh/git-best-practices-for-beginners-1h3c</link>
      <guid>https://dev.to/guroosh/git-best-practices-for-beginners-1h3c</guid>
      <description>&lt;p&gt;Git and GitHub are essential tools for software development, yet many beginners avoid using them properly due to concerns about making mistakes. They worry about accidentally deleting production code, pushing secrets, or exposing poorly written code. However, the real problems that emerge are less dramatic but far more damaging: messy commit histories, abandoned branches, and a lack of context.&lt;/p&gt;

&lt;p&gt;This guide outlines simple, reliable practices that keep your workflow clean, predictable, and professional.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkih6z0mtlhu6a6x7h930.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkih6z0mtlhu6a6x7h930.png" width="799" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Essential Commands to Stay in Control
&lt;/h2&gt;

&lt;p&gt;Git provides numerous commands to check your repository status, and running them causes no harm. In fact, you should develop a habit of using them frequently:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. git status
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The most important command, &lt;strong&gt;use it obsessively&lt;/strong&gt; whenever you can.&lt;/li&gt;
&lt;li&gt;Shows your current branch, what has changed, which files are added, and how your commits compare to the remote origin.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. git pull
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Generally safe to run at any time, especially before starting a new task.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. git diff
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Useful for reviewing your unstaged changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. git log
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Useful for reviewing the commit history in your local repository.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Starting with a new Feature
&lt;/h2&gt;

&lt;p&gt;When beginning a new feature, first ensure everything is up to date:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status     &lt;span class="c"&gt;# Ensure you're on the main branch&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you’re not on the main branch, switch to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then continue with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git pull
&lt;span class="c"&gt;# Output example:&lt;/span&gt;
&lt;span class="c"&gt;# remote: Enumerating objects: 3, done.&lt;/span&gt;
&lt;span class="c"&gt;# ...&lt;/span&gt;
&lt;span class="c"&gt;# From github.com:repo/project&lt;/span&gt;
&lt;span class="c"&gt;#    a3c912d..e71b4ac  main       -&amp;gt; origin/main&lt;/span&gt;
&lt;span class="c"&gt;# Updating a3c912d..e71b4ac&lt;/span&gt;
&lt;span class="c"&gt;# Fast-forward&lt;/span&gt;
&lt;span class="c"&gt;#  README.md | 4 +++-&lt;/span&gt;
&lt;span class="c"&gt;#  1 file changed, 3 insertions(+), 1 deletion(-)&lt;/span&gt;

git pull     &lt;span class="c"&gt;# Run again to confirm&lt;/span&gt;
&lt;span class="c"&gt;# Already up to date.&lt;/span&gt;

git log      &lt;span class="c"&gt;# Optional, to check the latest commits in your local history&lt;/span&gt;

git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; a-new-branch-with-a-unique-name  &lt;span class="c"&gt;# -b to create a new branch&lt;/span&gt;

git status   &lt;span class="c"&gt;# Confirm you're on the new branch&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’re now ready to start coding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Name your Branches Clearly
&lt;/h2&gt;

&lt;p&gt;Avoid generic names like &lt;strong&gt;refactoring&lt;/strong&gt;, &lt;strong&gt;ui_update&lt;/strong&gt;, or &lt;strong&gt;bug_fix&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Branch names should aim to be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Informative: Clearly communicate the purpose&lt;/li&gt;
&lt;li&gt;Unique: Prevent accidental conflicts with existing branches&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;A few good examples of branch names:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;fixing-bug-payment-timeout-using-redis&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;feature/add-user-profile-with-updated-fields&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;task-123--fix-db-connection-issue&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If available, include the ticket/task number in the branch to ensure uniqueness and improve traceability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Commit and Push Frequently to Your Branch
&lt;/h2&gt;

&lt;p&gt;New developers hesitate to push code for various reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the code isn’t working yet&lt;/li&gt;
&lt;li&gt;they’re hiding unfinished work, or&lt;/li&gt;
&lt;li&gt;they fear accidental merges.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, pushing frequently to a feature branch is exactly what it’s designed for.&lt;/p&gt;

&lt;p&gt;Here’s how to do it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status                                 &lt;span class="c"&gt;# Ensure you're on the correct branch&lt;/span&gt;
git add app/config api/src README.md       &lt;span class="c"&gt;# Add only the files you want&lt;/span&gt;
git status                                 &lt;span class="c"&gt;# Verify what's staged (colored display)&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"A Good Commit Message"&lt;/span&gt;
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin HEAD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; If you are on the correct branch &lt;code&gt;git push -u origin HEAD&lt;/code&gt; will always work, no need to copy and paste the specific branch name.&lt;/p&gt;

&lt;h3&gt;
  
  
  After pushing, create a Pull Request (PR) immediately:
&lt;/h3&gt;

&lt;p&gt;New developers assume a PR should only be created when the work is finished. This is incorrect. Opening a PR early provides several benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A clear, visual summary of all ongoing changes&lt;/li&gt;
&lt;li&gt;An easy way to track progress as you develop&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;PRs are &lt;strong&gt;not&lt;/strong&gt; a sign of completion.&lt;/p&gt;

&lt;p&gt;In fact, most major Git platforms (GitHub, Azure Repos, etc.) offer &lt;strong&gt;Draft PRs&lt;/strong&gt; to prevent accidental merges and to signal that the work is still in progress.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkj167khlsrjqoak07p58.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkj167khlsrjqoak07p58.png" alt="Option to convert a PR to a Draft PR in Github" width="800" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Option to convert a PR to a Draft PR in Github&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fynwmeaefsoeroe5nxnyl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fynwmeaefsoeroe5nxnyl.png" alt="Option to Create a Draft PR in Azure DevOps" width="800" height="666"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Option to Create a Draft PR in Azure DevOps&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid adding all files to the staging area
&lt;/h2&gt;

&lt;p&gt;Blindly adding everything with &lt;code&gt;git add .&lt;/code&gt; risks pushing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OS-specific hidden files like .DS_Store&lt;/li&gt;
&lt;li&gt;Temporary artifacts&lt;/li&gt;
&lt;li&gt;Editor swap files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead, intentionally add specific files to the staging area:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add app/config app/utils api/src README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, as a long term solution &lt;code&gt;.gitignore&lt;/code&gt; should be used to avoid staging any unwanted files or folders.&lt;/p&gt;

&lt;p&gt;Even with a well-maintained &lt;code&gt;.gitignore&lt;/code&gt;, &lt;strong&gt;make it a habit&lt;/strong&gt; to add specific files deliberately rather than relying on &lt;code&gt;git add .&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing and Merging the PR
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Write Clear, Informative Commit Messages
&lt;/h3&gt;

&lt;p&gt;When it’s time to close the PR, the final commit message must be clean and informative. Individual commit messages on the branch won’t appear in the main history, so focus on the PR’s merge message.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;Good Commit Message&lt;/strong&gt; explains what changed and why. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bad: “UI changes”&lt;/li&gt;
&lt;li&gt;Better: “Update to hide unused sidebar buttons to simplify UI”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Git platforms like GitHub auto-generate merge commit messages and automatically reference PRs using &lt;code&gt;#&amp;lt;number&amp;gt;&lt;/code&gt;, which helps maintain a searchable history of closed PRs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Squash and Merge for Cleaner History
&lt;/h3&gt;

&lt;p&gt;When merging a pull request, use &lt;strong&gt;Squash and Merge.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fujq01ae96xi9obkaa85u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fujq01ae96xi9obkaa85u.png" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Benefits of Squashing and Merging:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your main branch history remains readable, each feature appears as a single commit.&lt;/li&gt;
&lt;li&gt;Individual features are easier to revert if needed by just reverting a single squashed commit.&lt;/li&gt;
&lt;li&gt;Developers can commit frequently on their branch without worrying about cluttering the main branch’s commit history.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Delete the Feature Branch After Merging
&lt;/h3&gt;

&lt;p&gt;After a PR is merged:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Delete the feature branch immediately.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tools like GitHub and Azure Repos retain the PR history, so nothing is lost.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhofkky8so5sdboae0jd8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhofkky8so5sdboae0jd8.png" alt="GitHub lets you know that a branch can be safely deleted" width="800" height="99"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;GitHub lets you know that a branch can be safely deleted&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3pz1irzhtbjto3mrb965.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3pz1irzhtbjto3mrb965.png" alt="Azure Repos recommends to delete the source branch when merging a PR" width="800" height="674"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Azure Repos recommeds to delete the source branch when merging a PR&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ideally, only the main branch and active work-in-progress branches should remain in the repository. This keeps the repository clean and prevents confusion by having abandoned branches.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hope this guide helps.&lt;/p&gt;

&lt;p&gt;If you’d like to explore more advanced Git concepts, workflows, and best practices, you can read my &lt;a href="https://dev.to/guroosh/git-best-practices-for-professionals-1ek5"&gt;Guide for Professional Developers&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>github</category>
      <category>software</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
