I would like to write a script that guarantees a successful Git checkout without intervention from the user. I don't mind dumping anything that cannot be solved without user intervention: for example, uncommitted changes. I do want to keep explicitly ignored files (I consider these to be "under version control").
I made a script based on the cornucopia of answers to How do you discard unstaged changes in Git? and fixing errors I encountered over time (similar to but not exactly the same as Unstaged changes left after git --reset hard and Ignoring “Your local changes to the following files would be overwritten by merge” on pull).
I am now concerned that my piecemeal script contains redundancies, or could be shortened. Are any of the following calls redundant?
cd /SOME/FOLDER
git clean -df & git checkout .
git stash
git stash clear
git checkout SOME-BRANCH # or git checkout -B SOME-REMOTE SOME-BRANCH [1]
# possibly followed by a manual call to: git pull --rebase SOME-REMOTE
[1] Could these calls be git checkout -f
and git checkout -fB
?