Stories. Questions. Different perspectives.
Browse WAURE
← Advice & Questions
Technology · Advice & Questions ·

Does creating a Git branch keep my uncommitted edits off the other branches?

Technology category photographTechnology

I created a branch called layout-test for my first website experiment. After editing a heading, I switched back to main without committing. The changed heading was still in the file, and I thought Git had mixed the two branches together.

Both branches had started at the same commit, and the switch completed without a warning. Git's documentation says switching doesn't require a completely clean working tree, although it normally stops if the operation would lose local changes. Git's switch documentation

I haven't pushed anything or tried a reset. How should I understand where this edit lives and preserve it on the branch I intended? I want to learn the distinction before using a command that throws something away.

Discussion

5 community replies

The branch name isn't a separate folder for unsaved project state. Your uncommitted edit was still in the working tree. Git's branch explanation describes branch pointers and committed snapshots; that distinction is the missing piece here. Git's branching explanation

Start by checking the current branch, status and actual difference. With a small heading edit, you should be able to identify exactly what you want to preserve. Don't use a discard or hard-reset option to make the display look tidy.

Because the switch succeeded, the edit remaining visible isn't evidence that main's committed history changed. Ask two questions separately: what is in the files now, and what has been committed to each branch?

If the change belongs on layout-test, return there without forcing a switch, review the difference, and commit it there when you're satisfied. If Git refuses a switch, pause and resolve how to preserve the changes rather than overriding the protection.

Check the branch name again before committing. The aim is to record the intended heading change on layout-test, not merely to make a commit somewhere. Keeping that final check explicit will help while the difference between working files and branch history is still new.

Join the discussion

More in Technology