Posts in category “Tips”

Git Aliases for Clean Commits

Today I'd love to introduce three useful Git aliases to maintain clean code and intelligent staging.

Quick Setup

# 1. Remove trailing whitespace from modified files
git config --global alias.cleanup '!git -c color.status=false status -s | grep -v "^D\|^.D" | cut -c4- | xargs -r -I {} sed -i "s/[[:space:]]*$//" {}'

# 2. Stage only substantive changes (ignore whitespace)  
git config --global alias.stagewhitespace '!git reset . && git add -N . && git diff -w -b | git apply --cached'

# 3. Combine both operations
git config --global alias.smartadd '!git cleanup && git stagewhitespace'

Usage

git cleanup         # Clean trailing spaces only
git stagewhitespace # Stage content changes only
git smartadd        # Clean + smart staging

What Each Alias Does

cleanup

  • Removes trailing whitespace from all modified files
  • Skips deleted files to avoid errors
  • Handles ANSI color codes in git status output

stagewhitespace

  • Resets staging area
  • Marks new files as intent-to-add
  • Stages only meaningful content changes
  • Ignores pure whitespace modifications

smartadd

  • Runs cleanup first, then stagewhitespace
  • One command for clean, intelligent staging

Key Features

  • Safe: Filters out deleted files to prevent errors
  • Smart: Handles new files correctly
  • Clean: Maintains consistent code formatting
  • Focused: Stages only substantive changes

Technical Details

The aliases handle several edge cases:

  • ANSI color codes in git output (disabled with -c color.status=false)
  • Deleted files that would cause sed errors (filtered with grep -v "^D\|^.D")
  • New untracked files (handled with git add -N)
  • Empty file lists (handled with xargs -r)

Perfect for teams that want clean commits without manual whitespace management.

Quick Tip: Get GitHub PR Diffs Easily

Need to share changes from a GitHub PR (even closed ones)? Just add .diff or .patch to the PR URL:

Original URL:

https://github.com/owner/repo/pull/123

For diff format:

https://github.com/owner/repo/pull/123.diff

For patch format:

https://github.com/owner/repo/pull/123.patch

Both work for open, closed, or merged PRs. Perfect for code reviews, investigations, or sharing changes with others.

For LLM/AI analysis: Use .diff format - it's cleaner and more standardized than .patch which includes extra email headers.

Fix Rider WinForms Designer Build Locks

Problem

Rider's WinForms Designer locks files, preventing builds. It is super annoying!

Solution

  1. File → Settings (Ctrl+Alt+S)
  2. Tools → Windows Forms Designer
  3. Uncheck "Enable Windows Forms Designer"
  4. Apply and restart Rider

Emergency Fix

Kill locked processes:

taskkill /IM dotnet.exe /F

Alternative

Use Visual Studio for form design, Rider for code.

WiFi Driver Fix for Mid-2010 MacBook Pro on Pop!_OS 22.04

# Remove conflicting B43 driver
sudo apt remove firmware-b43-installer

# Install Broadcom wireless driver
sudo apt install bcmwl-kernel-source

# Reset wireless modules
sudo modprobe -r b43 ssb wl
sudo modprobe wl

Troubleshooting

  • If WiFi doesn't work, reboot your system
  • Ensure you have the latest system updates

Note: This method resolves WiFi issues for my mid-2010 MacBook Pro. By the way, this driver has very good performance! I love this solution!!!

Windows Server 2022 RDP Connection Fix

Problem

  • Our IT security team has weird security setup, which successfully prevented the RDP client from remembering the password, and also caused the following annoying issue

    • RDP connection requires clicking "More choices" → "Use a different account" every time
    • Username not remembered despite saving in RDP file

Solution

Edit your .rdp file with these key settings:

full address:s:your-server-address, such as xetawsdev85.xemt.dev 
domain:s:XEMT 
username:s:your-username, such as David.Wei 
enablecredsspsupport:i:0

Key Points

  1. Separate domain and username - don't use XEMT\David.Wei format in RDP file
  2. Set authentication level:i:2 - forces proper authentication (this step has been proved not necessory)
  3. Disable CredSSP support - enablecredsspsupport:i:0 is essential (tested, this is the KEY option!)
  4. If you see a certificate warning on first connection - check "Don't ask me again"

Result

Username will be pre-filled correctly, only password entry required.