<?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: Ahmed_hamdy</title>
    <description>The latest articles on Forem by Ahmed_hamdy (@fluttersmith).</description>
    <link>https://forem.com/fluttersmith</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%2F2929007%2F65eed266-1bfa-4f25-a511-0b9a5a84f476.jpeg</url>
      <title>Forem: Ahmed_hamdy</title>
      <link>https://forem.com/fluttersmith</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/fluttersmith"/>
    <language>en</language>
    <item>
      <title>Git Mastery Cheatsheet: Level Up Your Git Game</title>
      <dc:creator>Ahmed_hamdy</dc:creator>
      <pubDate>Mon, 10 Mar 2025 17:21:17 +0000</pubDate>
      <link>https://forem.com/fluttersmith/git-mastery-cheatsheet-level-up-your-git-game-22l8</link>
      <guid>https://forem.com/fluttersmith/git-mastery-cheatsheet-level-up-your-git-game-22l8</guid>
      <description>&lt;p&gt;**Introduction to Git&lt;br&gt;
**Git is a powerful distributed version control system that lets you track changes, collaborate seamlessly, and maintain a robust project history. Whether you're new to Git or an experienced developer, this cheatsheet provides quick, essential references for both basic and advanced Git commands to enhance your workflow.&lt;/p&gt;

&lt;p&gt;Basic Git Commands&lt;br&gt;
Initialization&lt;br&gt;
Initialize a new Git repository in your current directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command creates a hidden &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;.git&lt;br&gt;
 directory that starts tracking your project.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Cloning a Repository&lt;br&gt;
Clone an existing repository from a remote source:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone &amp;lt;repository_url&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command downloads the repository to your local machine.&lt;/p&gt;

&lt;p&gt;Staging Changes&lt;br&gt;
Add files or directories to the staging area:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add &amp;lt;file_or_directory&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stage all modified files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Committing Changes&lt;br&gt;
Commit your staged changes with a message describing the update:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m "Your commit message"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Checking Repository Status&lt;br&gt;
See the current state of your repository, including staged, modified, and untracked files:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Viewing Differences&lt;br&gt;
View changes between your working directory and the staging area:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git diff

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See differences between the staging area and the last commit:&lt;/p&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
git diff --cached&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;br&gt;
`&lt;br&gt;
Branching&lt;br&gt;
Manage branches to work on multiple features simultaneously:&lt;/p&gt;

&lt;p&gt;Create a new branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch &amp;lt;branch_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Switch to an existing branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
git checkout &amp;lt;branch_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create and switch to a new branch in one step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout -b &amp;lt;branch_name&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Merge a branch into the current branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git merge &amp;lt;branch_name&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pushing and Pulling Changes&lt;br&gt;
Push your commits to a remote repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push &amp;lt;remote&amp;gt; &amp;lt;branch&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pull updates from the remote repository to your local branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git pull &amp;lt;remote&amp;gt; &amp;lt;branch&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Viewing Commit History&lt;br&gt;
List the commit history to review past changes:&lt;br&gt;
&lt;/p&gt;

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

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Advanced Git Commands&lt;br&gt;
Reverting Changes&lt;br&gt;
Undo changes by reverting a specific commit. This creates a new commit that reverses the changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git revert &amp;lt;commit_hash&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Resetting Commits&lt;br&gt;
Undo commits with different levels of rollback:&lt;/p&gt;

&lt;p&gt;Soft reset (keeps changes staged):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git reset --soft HEAD~1

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mixed reset (unstages changes):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git reset --mixed HEAD~1

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hard reset (discards all changes):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git reset --hard HEAD~1

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rebasing&lt;br&gt;
Reapply your commits on top of another branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rebase &amp;lt;branch_name&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stashing Changes&lt;br&gt;
Temporarily save uncommitted changes to work on something else:&lt;/p&gt;

&lt;p&gt;Stash changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reapply stashed changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash apply

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cherry-Picking&lt;br&gt;
Apply a specific commit from one branch onto the current branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git cherry-pick &amp;lt;commit_hash&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Git Hooks&lt;br&gt;
Customize Git's behavior with hooks. Place executable scripts in the .git/hooks directory (e.g., pre-commit, post-merge) to run custom actions before or after Git events.&lt;/p&gt;

&lt;p&gt;Git Aliases&lt;br&gt;
Create shortcuts for commonly used Git commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global alias.&amp;lt;alias_name&amp;gt; '&amp;lt;command&amp;gt;'

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global alias.co 'checkout'

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Git Workflows&lt;br&gt;
Adopt one of these common workflows to manage your project:&lt;/p&gt;

&lt;p&gt;Centralized Workflow: Single main branch for direct commits.&lt;br&gt;
Feature Branch Workflow: Separate branches for new features or fixes, merged back when complete.&lt;br&gt;
Gitflow Workflow: Structured branching model with dedicated branches for development (develop), releases (release), and features.&lt;br&gt;
Conclusion&lt;br&gt;
Mastering Git is essential for effective version control and collaboration. Use this cheatsheet as your quick reference guide to become more proficient with Git, streamline your workflow, and manage your projects with confidence.&lt;/p&gt;

&lt;p&gt;Connect with me on LinkedIn and follow my work on GitHub.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

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