Urgent.News

What's breaking now, across thousands of outlets.

Tech

Stop Stashing. Use a Second Working Directory for the Interruption.

"Can you look at the login bug on main? Five minutes." You are forty minutes into a feature, with edits in six files that do not compile yet. The usual answer is git stash , switch, fix, switch back, git stash pop — and a stash you forget about, or a pop that conflicts with something you did in between. There is a better tool, and it has been in Git since 2.5: a second working directory for the…

The article discusses the benefits of using Git worktrees to manage interruptions and improve workflow while developing. Instead of using the `git stash` command to temporarily save changes, it suggests creating a second working directory for the interruption. This involves checking out the feature branch into a new directory that shares the same .git database, allowing the original feature branch to remain untouched.

After completing the work in the new directory, the original branch can be returned to with no loss of context or conflicting changes. Git enforces that only one branch can be checked out in one worktree at a time, preventing race conditions. When the hotfix is merged, the worktree can be easily removed without affecting the main branch.

The article also highlights other use cases for worktrees, such as code reviews, long builds, and comparing versions. However, it cautions that worktrees should not be used as a substitute for branches when creating a sandbox for experiments with the .git itself.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Twelve Commits, One Regression, Four Test Runs: git bisect run

The test fails on main . It passed a week ago. Twelve commits landed in between, most of them documentation, and nobody remembers which one touched the code. You could read all twelve diffs.

  • git bisect tool finds regression-causing commit
  • Requires known bad, known good commits, and test
  • Test determines good/bad outcome, speeds up process

Undo a Git Commit: Two Questions Before You Type Anything

"How do I undo a commit?" has four correct answers and three wrong ones, and the difference is not the command — it is two questions you ask before typing anything: Where is the change?

  • If change is in working tree, use git restore file to revert edit
  • If staged change is unwanted, use git restore --staged file to unstage
  • If committed and not pushed, use git reset --soft HEAD~1 to move pointer

Git Remembers How You Resolved That Conflict — If You Let It

You rebase a long branch onto main . The first commit conflicts in config.yml ; you resolve it. The second commit touches the same lines and conflicts in exactly the same way . So does the third.

  • Git's rerere feature remembers past conflict resolutions.
  • Resolved conflicts in rebase make future merges easier.
  • Git requires manual inspection and staging after resolution.

More from Sunday 20 September →