The answer is simple, as already noted in comments: you must commit.
Can't I do it without committing? Something such that it holds its state, and in future when I checkout back again, it restores its state.
That something—the thing which holds state and restores it later—is called a commit.
You can use git stash
... but it works by making commits.
You can use git worktree
, which may be the correct answer to your particular desired work-flow. The mechanism that git worktree
provides is to add an additional working tree to some existing Git repository. This additional working tree does not affect any existing working tree, but there is a strong constraint on each added working tree: it must be on its own branch, or use Git's detached-HEAD mode. This constraint is met by your own starting requirements, so it's not a problem, but it is worth mentioning.
Each added working tree holds its own state. However, a working tree is not in Git, and cannot be extracted later from another clone. Only the commits are in Git. So eventually you must commit: the added working tree merely allows you to put off running git commit
.
As Romain Valeri notes in a comment, you can "reset" a commit away to get rid of it. Git doesn't actually discard the commit immediately: Git has a mechanism for recovering accidentally-deleted commits, vaguely similar to the "waste basket" icons on many desktops. But it will eventually go away, and because commits are generally quite cheap (in terms of disk space), you can just ignore this and let Git clean it up on its own later.