March 3, 2026  •  Comments

Git Cheat Sheet: Master the Workflow

Git can be complex, but with the right reference, it becomes a powerful ally. This cheat sheet is designed to be clear, visual, and comprehensive.

🛠️ Configuration & Setup

First things first: identify yourself to Git.

You can use --global to apply settings to all repositories on your system, or omit it for project-specific settings.

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

🚀 Repository Initialization

Start a new project or grab an existing one from the cloud.

git init
git clone <url>

🔄 Daily Workflow (Staging & Committing)

This is where the magic happens. Move your changes from the working directory to the repository.

Status Check

Always run git status before committing to see exactly what is being included.

git status
git add <file>
git commit -m "Descriptive message"

🌿 Branching & Merging

Branches are essential for working in parallel without affecting the main codebase (main).

Branching Concept

Think of a branch as a separate timeline. You can experiment, break things, and then, when you’re ready, integrate those changes back.
CommandAction
git branchList all local branches
git checkout -b <name>Create and switch to a new branch
git merge <name>Merge branch <name> into current branch
git branch -d <name>Safely delete a merged branch

🏗️ Pull Requests (PRs)

A Pull Request is the way you propose changes to a repository and ask others to review them before they are integrated.

PR Merge Types:

Use Draft Pull Requests if you want to showcase your work-in-progress but aren’t ready for official review yet.

🛠️ Workflow

The most common workflow on platforms like GitHub or SourceHut is:

  1. Fork: Create a copy of the repository in your own account.
  2. Clone: Download your copy locally: git clone <url>.
  3. Branch: Create a branch for your change: git checkout -b my-improvement.
  4. Commit: Make your changes and save them: git commit -am "Add X".
  5. Push: Upload the branch to your remote: git push origin my-improvement.
  6. PR: Open a Pull Request from the platform’s web interface.

🌐 Remote Operations

Sync your local work with a remote server (like GitHub or SourceHut).

git remote -v
git push origin <branch>
git pull origin <branch>

⏪ Undoing Changes

Mistakes happen. Here is how to fix them.

Caution

Be careful with --hard resets, as they permanently discard uncommitted changes.

📦 Stashing

Need to switch branches but not ready to commit? Stash it!

git stash
git stash pop

🔍 Inspection & Logs

Understand the history of your project.

git log --oneline --graph --all
git diff --staged

🎓 Advanced Mastery

If you ever “lose” a commit after a bad reset, git reflog is your best friend. It tracks every move of the HEAD.

Comments

This blog uses a public mailing list for comments. Any message sent to the list will be publicly visible. You can join the discussion by viewing the archive or replying via email.

View Archive