<?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: Guroosh</title>
    <description>The latest articles on Forem by Guroosh (@guroosh).</description>
    <link>https://forem.com/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>Forem: Guroosh</title>
      <link>https://forem.com/guroosh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/guroosh"/>
    <language>en</language>
    <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://forem.com/guroosh/git-best-practices-for-professionals-1ek5</link>
      <guid>https://forem.com/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://forem.com/guroosh/git-best-practices-for-beginners-1h3c</link>
      <guid>https://forem.com/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>
