Switch branch and ignore any changes without committing

Following is the way to do this:

git stash save
git checkout branch
// do something
git checkout oldbranch
git stash pop

Indeed what it says (to be complete):
git stash save OR git stash (when in working branchY)
then git checkout branchX do something on branchX such as git add/commit -m etc.
git checkout branchY again and
git stash pop to get back the stash




How to undo ‘git add’ before commit on git ?

We can undo git add before commit with the following command ..

git reset

Which will remove it from the current index (the “about to be committed” list) without changing anything else.

We can also use

git reset

without any file name to unstage all due changes. This can come in handy when there are too many files to be listed one by one in a reasonable amount of time.